VBA Array Lookup

gehusi

Board Regular
Joined
Jul 20, 2010
Messages
182
I have two cells (say B3 and D3) on Sheet1 which I would like to concatenate. On Sheet3 are columns (say A and B) which hold the values of previous entries of those two cells. I would like a macro which checks if the current concatenated value exists in those columns. If it finds a match, it should prompt the user to confirm an overwrite of the data in the matched row.

I hope that makes sense. Thanks in advance!
 

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.
I have two cells (say B3 and D3) on Sheet1 which I would like to concatenate. On Sheet3 are columns (say A and B) which hold the values of previous entries of those two cells. I would like a macro which checks if the current concatenated value exists in those columns. If it finds a match, it should prompt the user to confirm an overwrite of the data in the matched row.

I hope that makes sense. Thanks in advance!

Give this a shot:

Code:
Sub checkRes()
Dim sh1 As Worksheet, sh2 As Worksheet, lr As Long, rng As Range
Set sh1 = Sheets(1)
Set sh2 = Sheets(2)
lr = sh2.Cells(Rows.Count, 1).End(xlUp).Row
Set rng = sh2.Range("A2:A" & lr)
For i = 2 To lr
If sh1.Range("B3").Value & sh1.Range("D3").Value = sh2.Cells(i, 1).Value & sh2.Cells(i, 2).Value Then
MsgBox "CHECK FOR OVERWRITE AT SHEET2, RANGE(" & Range(sh2.Cells(i, 1), sh2.Cells(i, 2)).Address & ")"
End If
Next
End Sub
Code:
 
Upvote 0

Forum statistics

Threads
1,214,591
Messages
6,120,425
Members
448,961
Latest member
nzskater

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