Indexing a row in a named range

bailey537

Board Regular
Joined
Jun 30, 2008
Messages
65
Hi

I am trying to do a loop of a named range while comparing to the same indexed value of a different named range i.e compare the first cell in one range to the first cell in a different range and then move to the next one in both.

However i dont know how to move to the next cell in the range that I am comparing the looped range with. I am using

Set j = Range("Start")
For Each c In Range("End").Cells
s = j.Row
e = c.Row
Next c

And i need a line in there to move to the next j. Any help?
 

Excel Facts

What is =ROMAN(40) in Excel?
The Roman numeral for 40 is XL. Bill "MrExcel" Jelen's 40th book was called MrExcel XL.
Are the range names the same size and shape? If so, I would just use indexes to iterate thru the ranges rather than For Each ie:

Code:
For i = 1 to Range("myRange").Rows.Count
  For j = 1 to Range("MyRange").Columns.Count
    If Range("myRange").Cells(i,j) = Range("MyOtherRange").Cells(i,j) Then '...
  Next j
Next i
 
Upvote 0
yes they will be the same size and shape, but i dont want to compare all of the second range to the first as your code does, would a do until end of the 1st range work and then increment the index of both within the loop
 
Upvote 0
Which rows/columns do you want to run the comparison on? Is it pre-defined or do you only know this at run-time? If it is dynamic (ie at runtime) please explain what determines which cells need to be tested/compared.
 
Upvote 0
Basically the are two predetermined named ranges, 1 column wide by x rows(where x is the same for both ranges). I want to cycle through both of them to get the number of the row of each row in the both ranges so i can assign an equation to another cell that sums between the two. I am using name ranges because the distance between them changes and I cannot combine the two ranges because I am using one of them in another part of the project that is independant of the second range.
 
Upvote 0
Solved it, Thanks very much for your response, used your idea of a loop within a loop, but conditioned it so that it ignored the compaisons that i didn't want. Cheers
 
Upvote 0

Forum statistics

Threads
1,213,562
Messages
6,114,322
Members
448,564
Latest member
ED38

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