Forum Discussion
JonHowarth
Oct 07, 2022Copper Contributor
Create button to jump to a cell
I have a sheet that tracks purchase order numbers in a table. I'd like to add a search function at the top of the spreadsheet, where you enter the PO number in a cell then press a search button and i...
- Oct 07, 2022
In the attached file you can enter the PO number in cell B1 and click the button in cell C1 to activate the cell with the PO number from B1. The macro currently searches for PO numbers in range A4:A1000 which can be adapted.
Sub activate_po_number() Dim i As Long On Error GoTo errormessage If Not IsError(i = WorksheetFunction.Match(Range("B1").Value, Range("A4:A1000"), 0)) Then i = WorksheetFunction.Match(Range("B1").Value, Range("A4:A1000"), 0) Cells(i + 3, 1).activate Else errormessage: MsgBox ("PO number not found") End If End Sub
OliverScheurich
Oct 07, 2022Gold Contributor
In the attached file you can enter the PO number in cell B1 and click the button in cell C1 to activate the cell with the PO number from B1. The macro currently searches for PO numbers in range A4:A1000 which can be adapted.
Sub activate_po_number()
Dim i As Long
On Error GoTo errormessage
If Not IsError(i = WorksheetFunction.Match(Range("B1").Value, Range("A4:A1000"), 0)) Then
i = WorksheetFunction.Match(Range("B1").Value, Range("A4:A1000"), 0)
Cells(i + 3, 1).activate
Else
errormessage:
MsgBox ("PO number not found")
End If
End Sub
- JonHowarthOct 07, 2022Copper ContributorThat works perfectly! Do you know how I can make it so the cell it scrolls to is the top row? At the moment, it scrolls to the cell in the middle of the page.