reference multiple tables within search range

Icesurf3r

New Member
Joined
Feb 13, 2013
Messages
39
I'm using the below code to check for existing records (in case the user of my UserForm clicks "add record" instead of "Update"

Code:
'Checks for existing record in case user clicks Add record instead of update.
Dim reference As String
reference = UserForm1.Ref_Num.Value
Dim aCell As Range




'Set aCell = Sheets("Tracker").Range("Table_Main[Reference Number]") &
Set aCell = Sheets("Go").Range("Table_Go[Reference Number]").Find(What:=reference, LookIn:=xlValues, _
    LookAt:=xlWhole, SearchOrder:=xlByRows, SearchDirection:=xlNext, _
    MatchCase:=False, SearchFormat:=False)


    If Not aCell Is Nothing Then
        MsgBox "This record already exists" & vbNewLine & "Please select Update instead", vbCritical = vbOKOnly, "Warning"
        Exit Sub
    End If

The code works as it should, however I can't figure out how to reference the other 5 tables (which are on separate sheets) in the same sub routine as I need to search the reference number column of each table to see if there's a match.

If anyone could help I would appreciate it.
 

Excel Facts

Which Excel functions can ignore hidden rows?
The SUBTOTAL and AGGREGATE functions ignore hidden rows. AGGREGATE can also exclude error cells and more.
How about
Code:
    Set aCell = Sheets("Go").Range("Table_Go[Reference Number]").Find(What:=reference, LookIn:=xlValues, _
        LookAt:=xlWhole, SearchOrder:=xlByRows, SearchDirection:=xlNext, _
        MatchCase:=False, SearchFormat:=False)
    If Not aCell Is Nothing Then
        MsgBox "This record already exists" & vbNewLine & "Please select Update instead", vbCritical = vbOKOnly, "Warning"
        Exit Sub
    End If
    
    Set aCell = Sheets("Tracker").Range("Table_Main[Reference Number]").Find(What:=reference, LookIn:=xlValues, _
        LookAt:=xlWhole, SearchOrder:=xlByRows, SearchDirection:=xlNext, _
        MatchCase:=False, SearchFormat:=False)
    If Not aCell Is Nothing Then
        MsgBox "This record already exists" & vbNewLine & "Please select Update instead", vbCritical = vbOKOnly, "Warning"
        Exit Sub
    End If
 
Upvote 0
You're welcome & thanks for the feedback.
 
Upvote 0

Forum statistics

Threads
1,223,240
Messages
6,170,951
Members
452,368
Latest member
jayp2104

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