# Help with For Each ..... Next Loop

#### abdul hafeel

##### New Member
I have a named ranges
eg
Range1 ="A1:C10" & Range2 = "A1:B1"

I need to find if the value in Range2 occurs in Range1.
I Ran the following code but it doesn't work. Pls help

Dim a, b, k As Integer
k = 0
a = 0
Do Until a = Range2.Columns.Count
b = 0
Do Until b = Range1.Rows.Count
For Each Range2(a+1, b+1) In Range1(a + 1, b + 1)
If p = pRange1(a + 1, b + 1) Then
k = k + 1
End If
Next Range2(a+1, b+1)
b = b + 1
Loop
a = a + 1
Loop

MsgBox k

### Excel Facts

Copy PDF to Excel
Select data in PDF. Paste to Microsoft Word. Copy from Word and paste to Excel.

#### Von Pookie

##### MrExcel MVP
What are you trying to do here? This is not coded correctly, whatever it is:
Code:
``For Each Range2(a+1, b+1) In Range1(a + 1, b + 1)``

Can't you just use COUNTIF?

Replies
4
Views
242
Replies
1
Views
74
Replies
5
Views
331
Replies
2
Views
988
Replies
6
Views
194

1,136,268
Messages
5,674,734
Members
419,523
Latest member
Urnovio

### 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.

### Which adblocker are you using?

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

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