I need help with VB(MS-Excel) code below. This code searches a value in a sheet and returns the column number associated with it in the active sheet. I am writing "If-Else" statement in the code, for the condition that when the value being searched is not found, a message should pop up saying "No data available". However I am getting error when this condition (value not found) is met. Request to please help me with this.
Sub findt()
Sheets(5).Select
Dim rFind As Range
With Range("A1:PZ1")
Set rFind = .Find(What:=Sheets(4).Range("C1").Value, LookAt:=xlWhole,
MatchCase:=False, SearchFormat:=False)
If rFind is nothing then MsgBox "No data available"
Else:Sheets(4).Range("C2").Value = rFind.Column
End if
End With
Sheets(4).Select
End Sub
Aucun commentaire:
Enregistrer un commentaire