Hey EXperta,
I used this code as below, but I am not getting the desired results, I am getting some columns above and not the exact ones....when I print out the FirstMatchRowNumber, it gives out row#5, whereas it should be 8 from K1, see the image as well
I used this code as below, but I am not getting the desired results, I am getting some columns above and not the exact ones....when I print out the FirstMatchRowNumber, it gives out row#5, whereas it should be 8 from K1, see the image as well
VBA Code:
Private Sub Worksheet_Activate()
' Find the last row number in column A.
Dim lastRow As Long
With Sheets("T2")
lastRow = .Cells(.Rows.Count, "K").End(xlUp).Row
End With
' Find the value you are looking for
lookupvalue = Worksheets("T2").Range("K1").Value
' Select the range you are looking in
lookuprange = Worksheets("T2").Range("K4:K26" & lastRow)
' Find the first matching value, and return the row number
' If there is no matching number, the macro will jump to "ErrorMessageBox"
On Error GoTo ErrorMesageBox
FirstMatchRowNumber = WorksheetFunction.Match(lookupvalue, lookuprange, 0)
MsgBox prompt:=FirstMatchRowNumber
' Go to the applicable row.
Worksheets("T2").Range("K" & FirstMatchRowNumber).Select
Exit Sub
' In case of an unknown number, the macro will show an message box
ErrorMesageBox:
MsgBox "The number entered in B1 is not known in A1:A" & lastRow
Exit Sub
End Sub
[/Code}