Go to cell in a column that matches the value of another cell

kivikatz

New Member
Joined
Sep 12, 2020
Messages
25
Office Version
  1. 365
Platform
  1. Windows
  2. MacOS
Hi all. I would like to add VBA code that scrolls to cell in a column which matches the value of another cell. For instance if a cell in Column A1:A100 matches cell B1, I would like to scroll down to the cell in Column A. Alternatively, is it possible if I manually click on cell B1 that it will scroll down to the matching cell in Column A.

I've searched around but cannot seem to find a solution. Thanks for all your help.
 
Ok, try
VBA Code:
      Set Fnd = Range("A:A").Find(Target.Value, , xlValues, xlPart, , , False, , False)
 
Upvote 0

Excel Facts

Bring active cell back into view
Start at A1 and select to A9999 while writing a formula, you can't see A1 anymore. Press Ctrl+Backspace to bring active cell into view.
The values are dates, and B1 is an exact match of the value found in column A. Thanks.
Are you sure the matches are identical? Right down to the split-second? Is it possible that due to formatting they only look alike, but that there are differences?
 
Upvote 0
I think so, but that's a good question. I've attached a sample sheet. Maybe I am missing something. Could it be that B1 uses XLOOKUP to find values in column A? Thanks.

Cell Formulas
RangeFormula
B1B1=IF(XLOOKUP(TRUE,C1:C100,A1:A100,"",0)>TODAY(),"",XLOOKUP(TRUE,C1:C100,A1:A100,"",0))
A2:A100A2=IF(TEXT(A1+1,"ddd")="Sat",A1+3,IF(TEXT(A1+1,"ddd")="Sun",A1+3,A1+1))
Cells with Conditional Formatting
CellConditionCell FormatStop If True
A:ACell Value=$B$1textNO
 
Upvote 0
Did you try the mod I suggested in post#11?
 
Upvote 0
not sure what I am doing wrong.
Probably nothing at all, working with dates & VBA can be a right PITA, especially for those of us who are not in the US.

try it like this
VBA Code:
      Set Fnd = Range("A:A").Find(Target.Text, , xlValues, xlPart, , , False, , False)
 
Upvote 0
Solution
Wow! That works great. Thanks for all your help.

By the way, can you suggest a VBA book or online course that's geared for newbies?
 
Upvote 0
You're welcome & thanks for the feedback.

I've never read any books or done tutorials so don't really know.
 
Upvote 0
VBA Code:
Sub Macro1()

' Find the last row number in column A.
    Dim lastRow As Long
    With Sheets("Sheet1")
        lastRow = .Cells(.Rows.Count, "A").End(xlUp).Row
    End With

' Find the value you are looking for
    lookupvalue = Worksheets("Sheet1").Range("B1").Value
 
' Select the range you are looking in
    lookuprange = Worksheets("Sheet1").Range("A1:A" & 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)

' Go to the applicable row.
    Worksheets("Sheet1").Range("A" & 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
Hey Peter,
I used your code as above, 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

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}
 

Attachments

  • snapshot.png
    snapshot.png
    10.7 KB · Views: 2
Upvote 0

Forum statistics

Threads
1,214,983
Messages
6,122,595
Members
449,089
Latest member
Motoracer88

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top