Your technology certification is waiting. Enroll in Cloud Class ®
Private Sub Worksheet_Change(ByVal Target As Range)
If Not Intersect(Range("A2"), Target) Is Nothing Then
ActiveSheet.Range("A4").Value = ActiveSheet.Columns("B:B").Find(Range("A2").Value).Row
Open in new window
MsgBox (getRow(ActiveSheet.Range("B2:C5"), 2, 5))
MsgBox (getRow(ActiveSheet.Range("B2:C5"), 2, 10))
Function getRow(rng As Range, theColumn as Long, theValue As Variant)
Dim r As Long
getRow = -1
For r = 1 To rng.Rows.Count
If rng.Cells(r, theColumn).Value = theValue Then
' Choose only one of the following assignments depending on what you want
' If you want the row with the range
getRow = r
' if you want the absolute row number in the worksheet
getRow = r + rng.Cells(1, 1).Row - 1
Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.
Have a better answer? Share it in a comment.
Please enter a first name
Please enter a last name
Must be at least 4 characters long.
Join and Comment
From novice to tech pro — start learning today.
Premium members can enroll in this course at no extra cost.