Here's a more condense version of what I'm trying to do with just one sheet. I have a method that returns a set of ranges and I just want to loop thru the ranges and set the Validation.InputMessage to a value. In this case the text "Please work". It loops thru the first time fine but the second time, I get an error.
Private Sub GenHoverText_Click()
Dim LastRow As Integer
Dim SearchRange As Range, SearchResults As Range, rng As Range
LastRow = activeSheet.UsedRange.row - 1 + _
activeSheet.UsedRange.Rows.Count
Set SearchRange = Worksheets("Sheet1").Range("A3:I20")
Set SearchResults = FindAll(SearchRange, "Search Value")
If SearchResults Is Nothing Then
'No match found
Else
For Each rng In SearchResults
Dim col, row As String
col = rng.Column
row = rng.row
rng.Validation.InputMessage = "Please work"
Next rng
End If
End Sub
Function FindAll(rng As Range, What As Variant, Optional LookIn As XlFindLookIn = xlValues, Optional LookAt As XlLookAt = xlWhole, Optional SearchOrder As XlSearchOrder = xlByColumns, Optional SearchDirection As XlSearchDirection = xlNext, Optional MatchCase As Boolean = False, Optional MatchByte As Boolean = False, Optional SearchFormat As Boolean = False) As Range
Dim SearchResult As Range
Dim firstMatch As String
With rng
Set SearchResult = .Find(What, , LookIn, LookAt, SearchOrder, SearchDirection, MatchCase, MatchByte, SearchFormat)
If Not SearchResult Is Nothing Then
firstMatch = SearchResult.Address
Do
If FindAll Is Nothing Then
Set FindAll = SearchResult
Else
Set FindAll = Union(FindAll, SearchResult)
End If
Set SearchResult = .FindNext(SearchResult)
Loop While Not SearchResult Is Nothing And SearchResult.Address <> firstMatch
End If
End With
End Function
Bookmarks