Hi Alfd,
I did record a macro which does the job I wanted but Im not able to
customize according to the changing number of rows in my data.
For ex. my data is in Raw data worksheet. I used another intermediate
worksheet called "Inter sheet" in which Im performing the advanced filter
and then sorting the data as per my specifications( coulmns selected for
sorting are always constant).
The problem I have is how to make the code variable ( not much experience
with coding)
Like while recording the macro based on data in Raw data worksheet I tried
recording with dummy data with no of rows ranging from B3 to V23.
But my actual no of rows could be 500 or 4300 or any variable number. Im not
sure how to introduce that variability. Please see my code below.
I have calculated the no of maximum rows as per my data conditions below in
the code ( I pinched this part from somebody else) using the variable
"rowcount" but
I dunno how to introduce rowcount in rest of the code.
Like I would have to replace --> Range("B3:V23").Select with a code where
range selected is from B3 to column V where the row number of column V would
be he variable rowcount.
I tried it as Range("B3:V&rowcount").Select
but Im getting "Method range of object global failed"
Please guide me.
Sub Macro1()
'
Dim rowcount As Integer
Dim ok As Integer
Dim gggg As String
gggg = "Raw Data"
Sheets(gggg).Select
Range("e3").Select
ok = 0
rowcount = 0
Do While ok = 0
ActiveCell.Offset(1, 0).Select
If ActiveCell.Value = "" Then
ok = 1
Else
rowcount = rowcount + 1
End If
Loop
rowcount = rowcount + 3
Sheets("Raw Data").Select
Range("B3").Select
Range(Selection, Selection.End(xlDown)).Select
Range("B3:V23").Select
Selection.Copy
Sheets("Inter. Sheet").Select
Range("B2").Select
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone,
SkipBlanks _
:=False, Transpose:=False
Range("T2").Select
Range(Selection, Selection.End(xlDown)).Select
Application.CutCopyMode = False
Selection.Cut
Selection.End(xlToLeft).Select
Selection.End(xlToLeft).Select
Selection.End(xlToLeft).Select
Selection.End(xlToLeft).Select
Range("C2").Select
Selection.Insert Shift:=xlToRight
ActiveWindow.SmallScroll ToRight:=-1
Range("B2").Select
Range("B1:C22").AdvancedFilter Action:=xlFilterInPlace, Unique:=True
Rows("2:21").Select
Selection.Sort Key1:=Range("U2"), Order1:=xlDescending,
Key2:=Range("M2") _
, Order2:=xlDescending, Key3:=Range("L2"), Order3:=xlDescending,
Header _
:=xlGuess, OrderCustom:=1, MatchCase:=False,
Orientation:=xlTopToBottom _
, DataOption1:=xlSortNormal, DataOption2:=xlSortNormal,
DataOption3:= _
xlSortNormal
Selection.Sort Key1:=Range("V2"), Order1:=xlDescending,
Key2:=Range("U2") _
, Order2:=xlDescending, Key3:=Range("M2"), Order3:=xlDescending,
Header _
:=xlGuess, OrderCustom:=1, MatchCase:=False,
Orientation:=xlTopToBottom _
, DataOption1:=xlSortNormal, DataOption2:=xlSortNormal,
DataOption3:= _
xlSortNormal
Range("B2:C21").Select
Selection.Copy
Sheets("Consolidation of Raw data").Select
Range("D3").Select
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone,
SkipBlanks _
:=False, Transpose:=False
End Sub
Regards,
Hari
India