Forum Discussion
katrina bethea
Aug 09, 2018Brass Contributor
macro messing up and i need help understanding VBA
this is not the entire vba as its a long recorded macro but when using step into this is the section that messes up. it hits the same error further down the sheet when it recorded the same filter but...
Lorenzo Kim
Aug 10, 2018Bronze Contributor
ActiveWorkbook.Worksheets("3 MONTH").AutoFilter.Sort.SortFields.Add2 Key:= _
Range("A1"), SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:= _
xlSortNormal
declare
Dim Lastrow as long
LastRow = Cells(Rows.Count, "A").End(xlUp).Row
I suspect that the Range is not declared right.. I think it should be Range("A1:A"&Lastrow)
then after
With ActiveWorkbook.Worksheets("3 MONTH").AutoFilter.Sort
you should declare the entire range say,
.SetRange Range("A1:S" & LastRow) ** where S is your last column
HTH
Range("A1"), SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:= _
xlSortNormal
declare
Dim Lastrow as long
LastRow = Cells(Rows.Count, "A").End(xlUp).Row
I suspect that the Range is not declared right.. I think it should be Range("A1:A"&Lastrow)
then after
With ActiveWorkbook.Worksheets("3 MONTH").AutoFilter.Sort
you should declare the entire range say,
.SetRange Range("A1:S" & LastRow) ** where S is your last column
HTH
- Lorenzo KimAug 10, 2018Bronze Contributortry this in a test workbook..
always have a back-up copy of your work- Lorenzo KimAug 10, 2018Bronze Contributor
attached is a sample file for your to test..
- Lorenzo KimAug 10, 2018Bronze ContributorI usually used the "Record Macro" for some repetitive tasks
then tweak the codes to make it work as required..
Like LEGO, make some modules, test them then plug it in...