ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Looking for range values in another range/sheet (https://www.excelbanter.com/excel-programming/341139-looking-range-values-another-range-sheet.html)

Przemek

Looking for range values in another range/sheet
 
Hi,
I've got following situation. I've got 2 sheets and I want to find
these rows in Sheet1, which contains values from Sheet 2 (2 cells in
row only). My idea is to first loop through rows in Sheet1 and inside
this loop have another loop through range from Sheet2. The problem is
how to read values from rows in Sheet2 to compare them with cells
values from Sheet1.

TIA

Przemek


Tom Ogilvy

Looking for range values in another range/sheet
 
Dim cell as Range, cell1 as Range, rw as Range
for each cell in Worksheets("Sheet1").Range("A1:A10")
if application.Countif(Worksheets("Sheet2").Range("B9 :F32"),cell.Value)
0 then
' a match exists, find it
for each rw in Worksheets("Sheet2").Range("B9:F32")
for each cell1 in rw.cells
if cell.value = cell1.value then
msgbox "Found at " & cell1.Address(0,0,xlA1,True)
end if
Next
Next
End if
Next

There are faster ways, but this does looping similar to your suggestion

--
Regards,
Tom Ogilvy


"Przemek" wrote in message
oups.com...
Hi,
I've got following situation. I've got 2 sheets and I want to find
these rows in Sheet1, which contains values from Sheet 2 (2 cells in
row only). My idea is to first loop through rows in Sheet1 and inside
this loop have another loop through range from Sheet2. The problem is
how to read values from rows in Sheet2 to compare them with cells
values from Sheet1.

TIA

Przemek





All times are GMT +1. The time now is 07:36 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com