searchColumn is a variable.
Having the Sub take arguments is one way to control it. Four lines would be removed and the declaration would be changed.
The start of the sub would look like
Sub FindStuff(searchFor as String, searchColumn As Range)
'Dim searchFor As String: Rem remove
'Dim searchColumn As Range: Rem remove
Dim foundCell As Range
Dim firstAddress As String
'Set searchColumn = ThisWorkbook.Sheets("sheet1").Range("A:A"):Rem remove
'searchFor = "a": Rem remove
With searchColumn
Set foundCell = .Find(What:=searchFor, _
After:=.Range("A1"), LookIn:=xlFormulas, LookAt:=xlPart, _
SearchOrder:=xlByRows, SearchDirection:=xlNext, MatchCase:=False)
Rem rest of code
End Sub
And then you could call the routine like
Sub MainRoutine()
Call FindStuff("Sam", ThisWorkbook.Sheets("Sheet1").Column("B"))
Call FindStuff("Dorothy", ThisWorkbook.Sheets("Sheet2").Range("D:E"))
End Sub
Note that all occurances of "Dorothy" is being found in both columns D and E. The search can be restricted to any continious range.
Bookmarks