Help with For Each ..... Next Loop

abdul hafeel

New Member
Joined
Oct 14, 2006
Messages
9
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
Joined
Feb 17, 2002
Messages
13,686
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?
 

Forum statistics

Threads
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.
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
Top