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 Kim
Aug 10, 2018Bronze Contributor
try this in a test workbook..
always have a back-up copy of your work
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...- katrina betheaAug 13, 2018Brass Contributor
i was using record macro. for some reason when it was recorded within a long macro it wouldn't work but when i recorded just the filter then created a master macro using the "call" command to insert the filter macro into the rest of it everything worked fine. even compared the coding and it was identical. doesn't make sense to me but its working from doing that. sorry didn't see your posts until today. not sure if what you did would work since i don't want to mess up what i have working now but maybe it will help someone else. been trying to teach myself VBA the past 2 weeks with no prior programming skills and it's been a hassle with google and excel's "step in-to" as my only resources.