Hi all,
As you're possibly aware, I'm fairly new to VBA but learning every day.
I have a couple of forms, one searches and clears a record/row and another that adds a record/row as lastrow + 1, once either of these have executed I have a few lines of code (below) that sort the sheet, firstly by custom order on column B, then alphabetically on column C.
My problem is that the Sub is ending with rows 3 to 22 selected when I click submit on both forms (both forms have these same lines of code at the end). I have tried various methods of selecting Cell A1 before EndSub but all are resulting in an error. I'm sure the issue is to do with the first line of code below - Rows("3:22").Select as the entirety of rows 3 to 22 are remaining selected.
Here is my code, hopefully someone more knowledgeable that me can throw in a line that deselects rows 3 to 22 and either results in (preferably) nothing being selected or cell A1 being selected.
Many thanks
As you're possibly aware, I'm fairly new to VBA but learning every day.
I have a couple of forms, one searches and clears a record/row and another that adds a record/row as lastrow + 1, once either of these have executed I have a few lines of code (below) that sort the sheet, firstly by custom order on column B, then alphabetically on column C.
My problem is that the Sub is ending with rows 3 to 22 selected when I click submit on both forms (both forms have these same lines of code at the end). I have tried various methods of selecting Cell A1 before EndSub but all are resulting in an error. I'm sure the issue is to do with the first line of code below - Rows("3:22").Select as the entirety of rows 3 to 22 are remaining selected.
Here is my code, hopefully someone more knowledgeable that me can throw in a line that deselects rows 3 to 22 and either results in (preferably) nothing being selected or cell A1 being selected.
Many thanks
VBA Code:
Rows("3:22").Select
ActiveWorkbook.Worksheets("DataSheet1").Sort.SortFields.Clear
ActiveWorkbook.Worksheets("DataSheet1").Sort.SortFields.Add2 Key:=Range( _
"B3").End(xlDown), SortOn:=xlSortOnValues, Order:=xlAscending, CustomOrder:= _
"WM,CM,FF", DataOption:=xlSortNormal
ActiveWorkbook.Worksheets("DataSheet1").Sort.SortFields.Add2 Key:=Range( _
"C3").End(xlDown), SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:=xlSortNormal
With ActiveWorkbook.Worksheets("DataSheet1").Sort
.SetRange Range("A3:BA22")
.Header = xlNo
.MatchCase = False
.Orientation = xlTopToBottom
.SortMethod = xlPinYin
.Apply
End With
Unload Me
End Sub