I was recently upgraded to Excel 2010 and one of my VBA codes has stopped working (use to run Excel 2007), and I am getting a subscript out of range error on the line in bold below.
Sub Search_Me()
'
'Based on the principle of the Find Method, This program will search for
'a string in the tag name colums of the Final Sortable List Page.
'The results of the search will be displayed by hiding the irrelevant
'data entries. To display the complete list, the User has to hit
'cancel or OK without making any entries to the textbox.
'
'Variable declaration
Dim iRow As Integer 'Number of rows in the dataset.
Dim iCol As Integer 'Column numbers that will be searched.
Dim iI As Integer 'Loop counter.
Dim bRow() As Boolean 'Row Formatting Array (True=Hit on Search Parameter).
Dim SearchString As String 'User's search request.
Dim LookInR As Variant 'Search range.
Dim FoundOne As Variant 'Intermittent search result.
Dim fAddress As Variant 'Address tag for first search result.
'Count number of rows in dataset. Using LOC column as marker
iRow = 6
Do
iRow = iRow + 1
Loop While (Cells(iRow + 1, 1).Value <> "")
ReDim bRow(6 To iRow) As Boolean 'Array redefined based on dataset size.
'Cleanup.
FinalList.Cells(2, 2).Value = Null
Rows("6:" & iRow).Hidden = False
FinalList.Range("B6:B" & iRow & ",E6:E" & iRow & ",L6:L" & iRow).Interior.Color = vbWhite
'Initiate search.
SearchString = Application.InputBox( _
"Enter Search parameter:" & Chr(10) & _
"You can search for a full tag name or a part of it." & Chr(10) & _
"Pressing OK without an entry or Cancel will clear the search results.", _
"Tag Name Search", , 100, 100, , , 2)
'Check for inpaaropriate selections.
If SearchString = "" Or SearchString = "False" Then Exit Sub
'Begin find method loop accross columns.
FinalList.Cells(2, 2).Value = SearchString
For iI = 1 To 5
'Make column selection based on iteration #.
Select Case iI 'Column Headings:
Select Case iI 'Column Headings:
Case 1
iCol = 2 'UNIT
Case 2
iCol = 3 'EQUIPMENT
Case 3
iCol = 6 'TAGNAME 1
Case 4
iCol = 13 'TAGNAME 2
Case 5
iCol = 20 'TAGNAME 3
End Select
'Set the search range based on the selected column.
'Searchable text starts on row 6
Set LookInR = FinalList.Range(Cells(6, iCol), Cells(iRow, iCol))
'Begin Find Method. (referenced from example in Help Files)
With LookInR
Set FoundOne = .Find(What:=SearchString, LookIn:=xlPart) 'Find the first hit.
If Not FoundOne Is Nothing Then
fAddress = FoundOne.Address 'Record the location of the first hit.
'Loop and record hits till the method finds the first hit again.
Do
'FoundOne.Interior.Color = vbYellow ':Used only during debug.
bRow(FoundOne.Row) = True ':Used for data formatting.
Set FoundOne = .FindNext(FoundOne) 'Find the next hit.
Loop While Not FoundOne Is Nothing And FoundOne.Address <> fAddress
End If
End With
Next iI
'Final Data Formatting.
For iI = 7 To iRow
FinalList.Rows(iI).Hidden = Not (bRow(iI)) 'Hide all rows without any hits on them.
Next iI
End Sub


Reply With Quote
