VBA Find Value from one Range in another Range

xrobc

New Member
Joined
Feb 25, 2015
Messages
27
I am in need of some help to do this in VBA.

I have a range of values in a Workbook1.Sheet1.F2:F1048576.

I wish to check if any of these values appears in a second range in Workbook2.Sheet1.A2:A1048576.

(The actual length of each of both ranges will vary, hence why I've used the full length of the Spreadsheet).

If found, return the found value (activecell.value) to a named cell reference (called "Con_no") in Workbook2.

Thanks
 

Excel Facts

Excel Can Read to You
Customize Quick Access Toolbar. From All Commands, add Speak Cells or Speak Cells on Enter to QAT. Select cells. Press Speak Cells.
All I have to do now is get it working with different workbooks:

VBA Code:
Sub BoM_has_con()

    Dim Has_Con       As Variant
    Dim Con_Range     As Variant
    Dim i             As Long
    Dim j             As Long
    
    Has_Con = Range("F2", Cells(Cells(Rows.Count, "F").End(xlUp).Row, "F")).Value
    
    Worksheets("ShtLookup").Activate
    Con_Range = Range("G2", Cells(Rows.Count, "G").End(xlUp))
    Worksheets("ShtPrepare").Activate
    
    For i = 1 To UBound(Has_Con)
      For j = 1 To UBound(Con_Range)
      
        If Has_Con(i, 1) = Con_Range(j, 1) Then Range("A30").Value = Con_Range(j, 1)

      Next j
    Next i

    Range("F2").Resize(UBound(Has_Con)).Value = Has_Con
    
End Sub
 
Upvote 0

Forum statistics

Threads
1,215,045
Messages
6,122,840
Members
449,096
Latest member
Erald

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