Search for a string, find the column and use that column to sort by
Sub findSort()
Dim findWhat As String, col As Integer
findWhat = "Johnny"
On Error GoTo errHandler
col = Cells.Find(What:=findWhat, After:=Cells(1, 1), _
LookIn:=xlFormulas, LookAt:=xlWhole, _
SearchOrder:=xlByRows, SearchDirection:=xlNext, _
MatchCase:=False, SearchFormat:=False).Column
Cells.Sort Key1:=Columns(col), Order1:=xlAscending, _
Header:=xlGuess, OrderCustom:=1, MatchCase:=False, _
Orientation:=xlTopToBottom, DataOption1:=xlSortNormal
Exit Sub
errHandler:
MsgBox findWhat & " not found"
End Sub
wrote:
I have a data dump into excel, but the info doesn't dump into the same
column everytime, so I need to search the sheet for that string and
once I find the column, use that column to sort the data.
|