Thursday, January 12, 2012

find and replace in batch in excel

Sub ReplaceText()
 'value to replace in D, value to be replaced by in E
For Each vCell In Range("d1:d49").Cells 'range to replace b
Columns("b:b").Cells.Replace What:=vCell, Replacement:=vCell.Offset(0, 1).Value, LookAt:=xlPart, _ SearchOrder:=xlByRows, MatchCase:=False, SearchFormat:=False, _ ReplaceFormat:=False Next vCell
End Sub

Tuesday, November 1, 2011

alpha lattice design

Background Design: cycdesign alphagen alpha+ R (agricolae) SAS (plan?) Analyse: With SAS proc lattice package (agricolae)

Wednesday, September 14, 2011

R index search and subset data

ind<-which(x$a>.5 & x$b>.5)

subset<-x(ind,)

Wednesday, September 7, 2011

Histogram in excel

Use Frequency function and Command Enter or Ctrl Shift Enter to populate through all bins...

Wednesday, September 29, 2010

Move multiple rows to Coulmns

Problem:

I took data from field which are like this

18-11

16-11

4-11

31-13

1-6

7-10

34-11

5-16

3

_

3

_

3

3

1

2

26-16

4-14

26-1

18-9

27-15

15-7

28-13

26-14

3

3

3

5

7

1

5

1

but I want convert it to

18-11 3
16-11 _
4-11 3
31-13 _
1-6 3
7-10 3
34-11 1
5-16 2
26-16 3
4-14 3
26-1 3
18-9 5
27-15 7
15-7 1
28-13 5
26-14 1

 

So, here is the macro

Sub alternateRowsToCol()
    Application.ScreenUpdating = False
    Dim row, col As Integer
    row = Sheets("Sheet3").UsedRange.Rows.Count
    col = Sheets("Sheet3").UsedRange.Columns.Count
    
    
    For i = 1 To row Step 2
    Sheets("Sheet3").Activate
  
    Sheets("Sheet3").Range("A" & CStr(i) & ":X" & CStr(i + 1)).Select
    ' X here is because I have 24 rows but in example just 8
    Selection.Copy
    Sheets("Sheet4").Activate
  
    Sheets("sheet4").Range("A" & CStr(24 * ((i - 1) / 2) + 1)).Select
    ' 24 here is because I have 24 rows but in example just 8
    Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks:= _
        False, Transpose:=True
  
    Next i
    Application.ScreenUpdating = True
   
End Sub

Thursday, June 3, 2010

Insert n rows after each row in EXCEL

image

image

Sub InsertRows()
Application.ScreenUpdating = False
Dim numRows As Integer
Dim r As Long
r = Cells(Rows.Count, "A").End(xlUp).Row
numRows = 2
For r = r To 1 Step -1
Worksheets(4).Rows(r + 1).Resize(numRows).Insert
Next r
Application.ScreenUpdating = True
End Sub

split a word with

Have you ever needed to split a word with certain character, yes I do, Mostly with _ or -

here you go, an excel macro

Function split1(text) 

split1 = Split(text, "_")(0)

End Function

Function split2(text)

split1 = Split(text, "_")(1)

End Function