+ Reply to Thread
Results 1 to 3 of 3

Extend COLORFUNCTION to query a 2nd condition

  1. #1
    Registered User
    Join Date
    09-05-2019
    Location
    N/A
    MS-Off Ver
    For Mac 16.26
    Posts
    10

    Smile Extend COLORFUNCTION to query a 2nd condition

    Hey there,

    I'm using this Colorfunction VBA from ozgrid

    Function ColorFunction(rColor As Range, rRange As Range, Optional SUM As Boolean)
    Dim rCell As Range
    Dim lCol As Long
    Dim vResult
    lCol = rColor.Interior.ColorIndex
    If SUM = True Then
    For Each rCell In rRange
    If rCell.Interior.ColorIndex = lCol Then
    vResult = WorksheetFunction.SUM(rCell, vResult)
    End If
    Next rCell
    Else
    For Each rCell In rRange
    If rCell.Interior.ColorIndex = lCol Then
    vResult = 1 + vResult
    End If
    Next rCell
    End If
    ColorFunction = vResult
    End Function
    However, I want to sum cells that not only have a certain background color, but also have a certain value in an adjacent cell. Is there a way to do this by editing the VBA? Or another method?

    Have attached a sample, where in cell C11, I want to sum cells that are blue AND rank = 1 in column A.
    Have entered expected results in red text.

    Thanks for the help in advance!

    Leaflock_sample.xlsm
    Last edited by Leaflock; 09-22-2022 at 06:19 PM.

  2. #2
    Forum Expert Crooza's Avatar
    Join Date
    10-19-2013
    Location
    Hunter Valley, Australia
    MS-Off Ver
    Excel 2003 /7/10
    Posts
    2,082

    Re: Extend COLORFUNCTION to query a 2nd condition

    This seems to work

    Function formula will look like this with an added array for your rankings (red) and an added range for the rank you want to filter on (blue)

    Please Login or Register  to view this content.

    the code looks like this
    Please Login or Register  to view this content.
    Last edited by Crooza; 09-22-2022 at 03:26 AM.
    Happy with my advice? Click on the * reputation button below

  3. #3
    Registered User
    Join Date
    09-05-2019
    Location
    N/A
    MS-Off Ver
    For Mac 16.26
    Posts
    10

    Re: Extend COLORFUNCTION to query a 2nd condition

    That worked like a charm! Thank you so much Crooza!

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. countif and colorfunction
    By Ribband in forum Excel Formulas & Functions
    Replies: 1
    Last Post: 12-31-2018, 07:46 AM
  2. [SOLVED] Extend copy range of a macro in a query file
    By Consty1 in forum Excel Programming / VBA / Macros
    Replies: 9
    Last Post: 06-30-2013, 04:34 PM
  3. [SOLVED] SUMIF + ColorFunction
    By Caulerpa in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 06-23-2013, 07:57 PM
  4. Colorfunction formula
    By dilemmax in forum Excel Formulas & Functions
    Replies: 3
    Last Post: 02-20-2013, 12:59 PM
  5. Can you use VLookup with ColorFunction?
    By PLCI in forum Excel General
    Replies: 1
    Last Post: 05-17-2011, 06:30 PM
  6. Possible to have ColorFunction & Sumproduct together?
    By unley in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 02-21-2011, 05:40 PM
  7. [SOLVED] how to extend data to next sheet automatically during sql query
    By Asha in forum Excel General
    Replies: 1
    Last Post: 10-13-2005, 02:05 PM

Tags for this Thread

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