This Sub is part of a large macro, but isolates the problem. It also runs independently as a call, as does the others like SortOHRows, SortMDRows, etc. because I'm not smart enough to compile them into ONE Sub!
Nearly 100% of the time the rows with CA in column F are alphanumerically first. There's only 3 states that are before CA, but are uncommon for us. Hence the problem.
After the macro compiles and edits the file records it sorts the entire file by state (column F). Then there are certain states where individual Subs are called, like the one for CA below, SortCARows, to sort those states now by phone (column C). No matter what I do, the very first record in the raw file with CA in column F sorts up to row 1 and is ALWAYS ignored when the Sub below is called, regardless of the phone number. ALL other Subs for different states always sort all rows, for any given state, by phone (column C).
All I can think of is that Excel thinks the first row is a header row, even though I even changed the code .Header = xlGuess to .Header = xlNo.
Thanks, in advance, for anyone that can help!
Nearly 100% of the time the rows with CA in column F are alphanumerically first. There's only 3 states that are before CA, but are uncommon for us. Hence the problem.
After the macro compiles and edits the file records it sorts the entire file by state (column F). Then there are certain states where individual Subs are called, like the one for CA below, SortCARows, to sort those states now by phone (column C). No matter what I do, the very first record in the raw file with CA in column F sorts up to row 1 and is ALWAYS ignored when the Sub below is called, regardless of the phone number. ALL other Subs for different states always sort all rows, for any given state, by phone (column C).
All I can think of is that Excel thinks the first row is a header row, even though I even changed the code .Header = xlGuess to .Header = xlNo.
Code:
Sub SortCARows()
Dim bottomF As Long
bottomF = Range("F" & Rows.count).End(xlUp).Row
Dim FirstRow As Long
Dim lastrow As Long
FirstRow = Range("F1:F" & bottomF).Find(What:="CA", LookAt:=xlWhole, SearchOrder:=xlByRows, SearchDirection:=xlNext).Row
lastrow = Range("F1:F" & bottomF).Find(What:="CA", LookAt:=xlWhole, SearchOrder:=xlByRows, SearchDirection:=xlPrevious).Row
Sheets("CurrentLeadFileUsing").Sort.SortFields.Clear
Sheets("CurrentLeadFileUsing").Sort.SortFields.Add Key:=Range("C" & FirstRow & ":C" & lastrow) _
, SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:=xlSortNormal
With Sheets("CurrentLeadFileUsing").Sort
.SetRange Range("A" & FirstRow & ":P" & lastrow)
.Header = xlNo
.MatchCase = False
.Orientation = xlTopToBottom
.SortMethod = xlPinYin
.Apply
End With
End Sub
Thanks, in advance, for anyone that can help!
Last edited: