nesting if and for to loops

ExcelEveryday1

New Member
Joined
Jan 7, 2016
Messages
20
I'm having trouble nesting loops!
How do I nest an "if statement" into a "for to" statement? Can anyone point me to a good place to check my nesting loops?



I'm essentially trying to populate a master list of numbers (z,1) by using matching criteria between two other lists. If two cells of others lists are equal to each other, it returns a certain value to the master(in the example, 5). If there is no match, than it moves to the next row, eventually next column, and eventually a down a row on the master list if there is no match in the other list.



Dim z As Long
Dim y As Long
Dim x As Long


For z = FirstRow To LastRow




For y = 1 To 4


For x = 11 To 40
If ... then
result
Else:
End If


Next x

If x = 40 Then
Next y


If y = 4 Then


Next Z
 

Excel Facts

How to find 2nd largest value in a column?
MAX finds the largest value. =LARGE(A:A,2) will find the second largest. =SMALL(A:A,3) will find the third smallest
remove the following lines

if x = 40 then
if y=4 then

Once the loops has reached their "to" values, they go to the next line of code anyway. Your statements were unnecessary and the way you did them meant they needed Endif statements
 
Upvote 0

Forum statistics

Threads
1,216,799
Messages
6,132,770
Members
449,760
Latest member
letonuslepus

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