+ Reply to Thread
Results 1 to 3 of 3

Change Conditional Formatting FORMULA Based on cell value. Could Use UDF User Defined Func

  1. #1
    Registered User
    Join Date
    09-05-2014
    Location
    Atlanta
    MS-Off Ver
    2010
    Posts
    6

    Change Conditional Formatting FORMULA Based on cell value. Could Use UDF User Defined Func

    I spent few hours finding this Online with NO luck. Hopefully someone here can help me.

    I have Table with 17 columns and 1000+ rows

    I am trying to set conditional formatting Based On Column Heading as Target. Formula Changes Based On Target Heading

    A Macro sorts the table based on heading.

    Conditional Formatting Formula Puts Borders On Rows by comparing cell value to cell value below in the the Target column.

    My conditional formatting formula is working fine but it's too long and may increase.

    Conditional Formatting Formula:

    =IF(SortBy_Code=2,$E2=OFFSET($E2,1,0),IF(SortBy_Code=3,$F2=OFFSET($F2,1,0),IF(SortBy_Code=4,$G2=OFFSET($G2,1,0),IF(SortBy_Code=5,$H2=OFFSET($H2,1,0),IF(SortBy_Code=6,$I2=OFFSET($I2,1,0),IF(SortBy_Code=7,$J2=OFFSET($J2,1,0),IF(SortBy_Code=8,$K2=OFFSET($K2,1,0),IF(SortBy_Code=9,$M2=OFFSET($M2,1,0),IF(SortBy_Code=10,$O2=OFFSET($O2,1,0),IF(SortBy_Code=11,$P2=OFFSET($P2,1,0),IF(SortBy_Code=12,$Q2=OFFSET($Q2,1,0),IF(SortBy_Code=13,$S2=OFFSET($S2,1,0),IF(SortBy_Code=14,$U2=OFFSET($U2,1,0),IF(SortBy_Code=15,$W2=OFFSET($W2,1,0),IF(SortBy_Code=16,$X2=OFFSET($X2,1,0),IF(SortBy_Code=17,$Z2=OFFSET($Z2,1,0)))))))))))))))))


    Broken down for easy reading

    =IF(SortBy_Code=0,$C2=$C2,
    IF(SortBy_Code=1,$C2=OFFSET($C2,1,0),
    IF(SortBy_Code=2,$E2=OFFSET($E2,1,0),
    IF(SortBy_Code=3,$F2=OFFSET($F2,1,0),
    IF(SortBy_Code=4,$G2=OFFSET($G2,1,0),
    IF(SortBy_Code=5,$H2=OFFSET($H2,1,0),
    IF(SortBy_Code=6,$I2=OFFSET($I2,1,0),
    IF(SortBy_Code=7,$J2=OFFSET($J2,1,0),
    IF(SortBy_Code=8,$K2=OFFSET($K2,1,0),
    IF(SortBy_Code=9,$M2=OFFSET($M2,1,0),
    IF(SortBy_Code=10,$O2=OFFSET($O2,1,0),
    IF(SortBy_Code=11,$P2=OFFSET($P2,1,0),
    IF(SortBy_Code=12,$Q2=OFFSET($Q2,1,0),
    IF(SortBy_Code=13,$S2=OFFSET($S2,1,0),
    IF(SortBy_Code=14,$U2=OFFSET($U2,1,0),
    IF(SortBy_Code=15,$W2=OFFSET($W2,1,0),
    IF(SortBy_Code=16,$X2=OFFSET($X2,1,0),
    IF(SortBy_Code=17,$Z2=OFFSET($Z2,1,0)
    ))))))))))))))))))

    I know I can create 17 individual condition formatting but that would be to much to track and change and it may increase

    I tried multiple ways to work around by using named range but no luck.


    I Also tried the following User Defined Function but it doesn't do anything.


    Function Show_ThinLine(SortBy_Code As integer, ThisCell As Range) As Boolean
    If SortBy_Code=3 then ' which is True
    If ThisCell.Value = ThisCell.Offset(1, 0).Value Then Show_ThinLine = True
    end if
    End Function

    Range selected: A2:Q1000 Whole Table without header and total rows
    Set Conditional Formattng Forumula to: =Show_ThinLine(3,$A2)=True , I tried A2, $A$2, Nothing would work
    Range $A2 could be anyone of the 2nd Row or 1st Table Row

    Forumula will work if put in cell but not in Conditional Formatting


    Thank You Anyone Who Tries

  2. #2
    Administrator FDibbins's Avatar
    Join Date
    12-29-2011
    Location
    Duncansville, PA USA
    MS-Off Ver
    Excel 7/10/13/16/365 (PC ver 2310)
    Posts
    52,933

    Re: Change Conditional Formatting FORMULA Based on cell value. Could Use UDF User Defined

    You do know that each rule in CF only applies to 1 color? So if you have 17 colors, you will need 17 rules

    Also, you could adjust teh OFFSET....
    =IF(SortBy_Code=0,$C2=$C2,
    IF(SortBy_Code=1,$C2=OFFSET($C2,1,0),
    IF(SortBy_Code=2,$E2=OFFSET($E2,1,0),
    IF(SortBy_Code=3,$F2=OFFSET($F2,1,0),
    IF(SortBy_Code=4,$G2=OFFSET($G2,1,0),
    IF(SortBy_Code=5,$H2=OFFSET($H2,1,0),
    to something like...
    OFFSET($C2,1,SortBy_Code)
    1. Use code tags for VBA. [code] Your Code [/code] (or use the # button)
    2. If your question is resolved, mark it SOLVED using the thread tools
    3. Click on the star if you think someone helped you

    Regards
    Ford

  3. #3
    Registered User
    Join Date
    09-05-2014
    Location
    Atlanta
    MS-Off Ver
    2010
    Posts
    6

    Re: Change Conditional Formatting FORMULA Based on cell value. Could Use UDF User Defined

    Do you mean put the following formula in conditional formatting?

    =OFFSET($C2,1,SortBy_Code),OFFSET($E2,1,SortBy_Code),OFFSET($F2,1,SortBy_Code)............

+ 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. Replies: 7
    Last Post: 06-07-2015, 04:59 PM
  2. Replies: 2
    Last Post: 02-22-2015, 11:52 AM
  3. Macro will not allow conditional formatting with a user-defined function
    By Med_MV in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 09-16-2013, 05:28 PM
  4. Conditional Formatting via VBA: Change formatting in range based on value of each cell
    By ralphjmedia in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 04-12-2013, 10:37 AM
  5. Conditional Formatting based on change in one cell
    By Jadvancing in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 01-28-2013, 06:45 PM
  6. conditional formatting to change colour of cell based on formula result
    By gideong in forum Excel Formulas & Functions
    Replies: 5
    Last Post: 03-15-2009, 09:35 AM
  7. how do i write and implement "pop-up" help for a user defined func
    By Velvetlady in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 08-02-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