Results 1 to 7 of 7

Comparing corresponding cells between multiple named ranges

Threaded View

  1. #1
    Registered User
    Join Date
    05-26-2012
    Location
    Georgia
    MS-Off Ver
    Excel 2010
    Posts
    4

    Comparing corresponding cells between multiple named ranges

    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.
    Last edited by Leith Ross; 05-26-2012 at 06:57 PM. Reason: Added Code Tags

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1