Use Sheet1:D5 to find matching cell in Sheet2 Column A:A, and select cell (or row)

brianv

Board Regular
Joined
Dec 11, 2003
Messages
128
I need to find a specific cell located in Column A:A on sheet 2 based on Sheet 1 D5, which is text based. I am not a code writer, but i find examples and work to modify them.

I need to select that Sheet2 cell in order to use it as a baseline to copy data from a "EditData" UserForm I have built. I have this built a 'NewEntry" Userform to add new data to a last row of a table based on using a "Find Last Row in Column A" macro.

So now i created a modified version of that "NewEntry" Userform to 'edit' existing data in a specific previous row of a table that corrosponds to the JobNumber listed in cell D5 on sheet1, so i need a starting point.

This was the original find last row code:
VBA Code:
Private Sub CmdSubmit_Click()
Dim iRow As Long
Dim ws As Worksheet
Set ws = Worksheets("Active")

Sheets("Active").Select
'find first empty row in database
iRow = ws.Cells(Rows.Count, 1) _
  .End(xlUp).Offset(1, 0).Row
 
'copy the data to the database
    ws.Cells(iRow, 1).Value = "Yes"

ws.Cells(iRow, 2).Value = Me.TextJobNumber.Value
ws.Cells(iRow, 3).Value = Me.TextProjectName.Value
ws.Cells(iRow, 4).Value = Me.TextAddress.Value
ws.Cells(iRow, 5).Value = Me.TextCSZ.Value
ws.Cells(iRow, 6).Value = Me.TextCustomer.Value
' Data continues for 20 cells...
    
    Range("B10").Select
        
    Sheets("Dashboard").Select
    Range("I6").Select

End Sub

So i tried to create a new macro to find a specific cell:
Code:
Sub FindTarget()

    Dim entry As String
    Dim mycol As Integer
    Dim myrow As Integer
    
    entry = Sheet1.Range("E7").Value
    mycol = Month(Now()) - 1
    myrow = Application.WorksheetFunction.Match(Range("e7"), Sheet1.Range("A1:A100"), 0)
    Sheet2.Range("a1").Select

End Sub
But im getting a runtime error.

Ultimately, this will reside in the UserForm code, I was just trying to get the code to 'find and select' the target cell first.

Any assistance is appreciated.

Thanks
BV
 

Excel Facts

Remove leading & trailing spaces
Save as CSV to remove all leading and trailing spaces. It is faster than using TRIM().
I got it working... found this on another post:

VBA Code:
Sub FindCell()

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

' Find the value you are looking for
    lookupvalue = Worksheets("Sheet2").Range("C4").Value
 
' Select the range you are looking in
    lookuprange = Worksheets("Sheet2").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("Sheet2").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
 
Upvote 0
Solution

Forum statistics

Threads
1,224,814
Messages
6,181,127
Members
453,021
Latest member
Justyna P

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