Excel 97 search macro help please
does it help to put the mycnt loop inside of the Sh loop:
For Each Sh In Sheets(SheetsToCheck)
For mycnt = 1 To UBound(myarray)
Set Found = Sh.Columns(myarray(mycnt)).Find(AssetNumber, _
LookIn:=xlFormulas, _
Lookat:=xlPart)
If Not Found Is Nothing Then
Found.Parent.Activate
Found.Activate
Exit For
End If
Next mycnt
Next Sh
"Charles Harmon" wrote:
Chris,
Not tested but try,
Option Base 1
Sub AssetNoSearch()
'
'AssetNoSearch Macro
'
'
Dim Found As Range
Dim Sh As Worksheet
Dim SheetsToCheck As Variant
Dim AssetNumber As String
Dim myarray As Variant
Dim mycnt As Integer
myarray = Array("H", "L", "N", "P", "R", "T")
Application.ScreenUpdating = False
SheetsToCheck = Array("DTP Hardware")
AssetNumber = Application.InputBox("Please Enter The Asset Number You _
Wish to Locate and either click on the <OK button and then hit <ENTER or _
hit <ENTER twice: ", _
"Find Asset Number")
For mycnt = 1 To UBound(myarray)
For Each Sh In Sheets(SheetsToCheck)
Set Found = Sh.Columns(myarray(mycnt)).Find(AssetNumber, _
LookIn:=xlFormulas, _
Lookat:=xlPart)
If Not Found Is Nothing Then
Found.Parent.Activate
Found.Activate
Exit For
End If
Next Sh
Next mycnt
If Found Is Nothing Then
MsgBox "Asset Number: " & AssetNumber & " does not exist."
End If
End Sub
"Chris Hankin" wrote in message
...
Hello,
I am trying to get the below macro to search column H of my workbook. It
works fine but i'd need it to also search columns: J, L, N, P, R, T. All
these columns have asset numbers.
Could someone please help me modifiy my existing code so that this may
happen.
All help is greatly appreciated.
Kind regards,
Chris.
Sub AssetNoSearch()
'
'AssetNoSearch Macro
'
'
Dim Found As Range
Dim Sh As Worksheet
Dim SheetsToCheck As Variant
Dim AssetNumber As String
Application.ScreenUpdating = False
SheetsToCheck = Array("DTP Hardware")
AssetNumber = Application.InputBox("Please Enter The Asset Number You
Wish to Locate and either click on the <OK button and then hit <ENTER or
hit <ENTER twice: ", _
"Find Asset Number")
For Each Sh In Sheets(SheetsToCheck)
Set Found = Sh.Columns("H").Find(AssetNumber, _
LookIn:=xlFormulas, _
Lookat:=xlPart)
If Not Found Is Nothing Then
Found.Parent.Activate
Found.Activate
Exit For
End If
Next Sh
If Found Is Nothing Then
MsgBox "Asset Number: " & AssetNumber & " does not exist."
End If
End Sub
|