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

Select a hidden cell
Somehide hide payroll data in column G? Press F5. Type G1. Enter. Look in formula bar while you arrow down through G.
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?
 
Upvote 0

Forum statistics

Threads
1,215,062
Messages
6,122,925
Members
449,094
Latest member
teemeren

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