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?
 

Some videos you may like

Excel Facts

Which Excel functions can ignore hidden rows?
The SUBTOTAL and AGGREGATE functions ignore hidden rows. AGGREGATE can also exclude error cells and more.

Richard Schollar

MrExcel MVP
Joined
Apr 19, 2005
Messages
23,707
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
 

bailey537

Board Regular
Joined
Jun 30, 2008
Messages
65
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
 

Richard Schollar

MrExcel MVP
Joined
Apr 19, 2005
Messages
23,707
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.
 

bailey537

Board Regular
Joined
Jun 30, 2008
Messages
65
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.
 

bailey537

Board Regular
Joined
Jun 30, 2008
Messages
65
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
 

Subscribe on YouTube

Watch MrExcel Video

Forum statistics

Threads
1,105,970
Messages
5,508,467
Members
408,687
Latest member
KevinNTU

This Week's Hot Topics

  • Turn fraction around
    Hello I need to turn a fraction around, for example I have 1/3 but I need to present as 3/1
  • TIme Clock record reformatting to ???
    Hello All, I'd like some help formatting this (Tbl-A)(Loaded via Power Query) [ATTACH type="full" width="511px" alt="PQdata.png"]22252[/ATTACH]...
  • TextBox Match
    hi, I am having a few issues with my code below, what I need it to do is when they enter a value in textbox8 (QTY) either 1,2 or 3 the 3 textboxes...
  • Using Large function based on Multiple Criteria
    Hello, I can't seem to get a Large formula to work based on two criteria's. I can easily get a oldest value based one value, but I'm struggling...
  • Can you check my code please
    Hi, Im going round in circles with a Compil Error End With Without With Here is the code [CODE=rich] Private Sub...
  • Combining 2 pivot tables into 1 chart
    Hello everyone, My question sounds simple but I do not know the answer. I have 2 pivot tables and 2 charts that go with this. However I want to...
Top