Traversing two named rages of unequal length

Z

zestpt

I created a function with help from this forum that allows you t
traverse an autofilter range.

With this function i created two ranges of unqeual length from th
autofilter ranges in two seperate workbooks.

My questions is this. How can i traverse through both of these range
at the same time using the format

for each rng in FilteredRange1
if rng in FilteredRange2 = value then
'do this
end if
next rng

thank
 
T

Tom Ogilvy

if the ranges are of unequal length, then why would the sequence in each be
a valid test.

in any event
i = 0
for each rng in FilterRange1
i = i +1
for each rng1 in FilterRange2
j = j + 1
if j = i then
if rng1 = value then
'do this
exit for
end if
end if
Next
Next
 
Z

zestpt

thanks tom, but even if they were of equal length. is there anyway t
traverse through the ranges without using counters? For example i wan
this code below to work without using a counter or nested for loops.

'Traverse range and put in value
For Each rng In PCR_AMTRange

'start populating, bypasses the header and don't populate pas
the range count
If rng <> "PCR_AMT" And counter
ObjSpreadSheetC.Range(IndexRangeName(r)).Count + 1 Then
ObjSpreadSheetC.Range(IndexRangeName(r))(counter) = rng
End If

counter = counter + 1
Next rn
 
T

Tom Ogilvy

There is no way to use a single for each construct on two separate ranges
where both ranges include multiple areas.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top