Newbie's first post.
I would like to compare corresponding cells between multiple named ranges. The named ranges all have the same cell count but are completely non-contiguous. Assuming that I have three named ranges, I want to compare the first cells from each named range and if a condition is met, increment a counter. Then I want to compare the corresponding second, third, fourth, and remaining cells from each named range, and update the counter accordingly. I couldn’t see how to do this using the “for each” loop or the “for” loop. In pseudo VBA code, this is what I’m thinking:
Function myFunction(ByVal range1 As Range, ByVal range2 As Range, ByVal range3 As Range)
Dim compCnt As Long
Dim c_rng1 As Range
Dim c_rng2 As Range
Dim c_rng3 As Range
c_rng1 = range1.Cells
c_rng2 = range2.Cells
c_rng3 = range3.Cells
loopCnt = range1.Count
For i = 1 To loopCnt
If (c_rng1.Value = "yes" And c_rng2.Value = "no" And c_rng3.Value = "yes") Then compCnt = compCnt + 1
' Somehow increment c_rng1, c_rng2 and c_rng3 to the next cell in the named range
Next i
myFunction = compCnt
End Function
(I think I could improve on the “if-then” statement by using WorksheetFunction.CountIf instead.)
Thanks for your help.
Bookmarks