I need to build a procedure in vba that looks in a column range - (example $B$2:$B$8) - and check if any of those cells contain the chars '*' OR '#', in order to get the Row where the first match/partial match happens.
I've adapted a code presented on this site by Rick Rothstein, where the purpose was to check for the values {2,3,4,5,6,7,8,9,10}, using
.
Suppose we have data in range [B2:B8] under the header "Total". I've adapted the Rick's Solution like this:
The code below just works on the value in cell [B5]. In my case it's correct because is the first ocurrence. But, if the value on [B5] was '24*', that didn't work.
Can anyone help please?
I've adapted a code presented on this site by Rick Rothstein, where the purpose was to check for the values {2,3,4,5,6,7,8,9,10}, using
Rich (BB code):
cells(Evaluate(Replace("MIN(IF( @={2,3,4,5,6,7,8,9,10},ROW(@)))", "@", Addr)), Found6.Column)
Suppose we have data in range [B2:B8] under the header "Total". I've adapted the Rick's Solution like this:
VBA Code:
Sub FindFirstOcurr_ValueIn_Rng()
'Find First Occurrence of Value in a Column
Dim LastRow As Long, Found6 As Range, FirstNumber As Range, Addr As String
Dim DataRow As Integer
'Look for column "Total", where values 2 to 10 are to be found
Set Found6 = cells.Find("Total", LookIn:=xlValues, LookAt:=xlWhole, MatchCase:=False)
If Found6 Is Nothing Then GoTo Skiddle
LastRow = cells(Rows.Count, Found6.Column).End(xlUp).row
Addr = cells(2, Found6.Column).Resize(LastRow - 1).Address
'Devolve a 1ª linha
'Set FirstNumber = cells(Evaluate(Replace("MIN(IF( @={2,3,4,5,6,7,8,9,10},ROW(@)))", "@", Addr)), Found6.Column)
DataRow = Switch(IsNumeric(Evaluate("MATCH(""~*""," & Addr & ",0)")), Evaluate("MATCH(""~*""," & Addr & ",0)"), True, 9999)
Skiddle:
End Sub
The code below just works on the value in cell [B5]. In my case it's correct because is the first ocurrence. But, if the value on [B5] was '24*', that didn't work.
Can anyone help please?