+ Reply to Thread
Results 1 to 12 of 12

Fill color in Range between specified value

  1. #1
    Registered User
    Join Date
    08-23-2007
    Posts
    58

    Fill color in Range between specified value

    Hello,


    Trying to find a way to fill in a color based on a specified value, up to the last entry.

    ie. Within a range ("Range1")T1:T9, anywhere the value is "R" , fill the color red within column P (offset -5 columns to the left) up to the last entry.

    ..this is something I would like to initiate via button assignment using a VBA script.

    eg:

    Column..P,.....T

    1..................B
    2........Red.....R
    3........Red.....T
    4........Red.....R
    5........Red.....V
    6........Red.....M
    7........Red.....R
    8..................X
    9..................X


    Thanks for any help


    ~Jeff

  2. #2
    Forum Expert shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2003, 2010
    Posts
    40,678
    Why not use conditional formatting?

  3. #3
    Registered User
    Join Date
    08-23-2007
    Posts
    58
    Thanks SHG,

    I had tried to incorporate Conditional Formatting, however I can only get as far as changing the format of the individual cell.

    I'm searching for a way to not only fill in the color between these values, but offset them as well

    Any ideas to accomplish this using Conditional formatting?


    ~Jeff

  4. #4
    Forum Contributor VBA Noob's Avatar
    Join Date
    04-25-2006
    Location
    London, England
    MS-Off Ver
    xl03 & xl 07(Jan 09)
    Posts
    11,988
    Select the range and enter

    =$T1="R"
    http://www.contextures.com/xlCondFormat02.html

    or code. Right click sheet and select view code

    Please Login or Register  to view this content.
    VBA Noob
    _________________________________________


    Credo Elvem ipsum etian vivere
    _________________________________________
    A message for cross posters

    Please remember to wrap code.

    Forum Rules

    Please add to your signature if you found this link helpful. Excel links !!!

  5. #5
    Forum Expert shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2003, 2010
    Posts
    40,678
    For the conditional formatting in column P, select P1:P9 and use the formula,

    =AND( ISNUMBER( MATCH("R", $T$1:$T1, 0) ), ISNUMBER( MATCH("R", $T1:$T$9) ) )

    ... and set the formatting you wish.
    Last edited by shg; 10-29-2007 at 03:22 PM.

  6. #6
    Registered User
    Join Date
    08-23-2007
    Posts
    58
    Thanks for the help!

    VBA Noob , I liked the code you provided, It offsets and marks red for the appropriate value, however it only fills that adjacent cell.

    ie:

    .........
    Red.....R
    Red.....R
    .........
    .........
    Red.....R
    .........
    .........

    as opposed to

    .........
    Red.....R
    Red.....R
    Red......
    Red......
    Red.....R
    .........
    .........





    shg,

    Thanks, using the conditional formatting method worked great!



    Thanks again for the help!

    Jeff

  7. #7
    Forum Expert shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2003, 2010
    Posts
    40,678
    You're welcome. I edited my prior post to a somewhat simpler formula.

  8. #8
    Registered User
    Join Date
    08-23-2007
    Posts
    58
    Hello,

    I have 2 follow up questions regarding conditional formatting,... If I may ?


    How can I modify the code to encompass a larger range?..
    currently the range of the code is between T1:T9.
    would like to adapt this to work between T16:T600 ? ( trying for several hours with unfavorable results)

    Also when a new row is inserted, the conditional formatting no longer works. (my workbook continually increases/decreases in size) Is there a workaround for this.? Perhaps to incorporate a named range?

    Thanks for any help


    Jeff

  9. #9
    Forum Expert Paul's Avatar
    Join Date
    02-05-2007
    Location
    Wisconsin
    MS-Off Ver
    2016/365
    Posts
    6,885
    Hello jeff.p,

    You should be able to modify shg's conditional formula. First, select the range P16:P600, then click Format -> Conditional Formatting.

    The new formula would be (I think):
    Please Login or Register  to view this content.
    As for the issue with inserting rows, if you go into Tools -> Options -> Edit tab, is 'Extend data range formats and formulas' checked?

  10. #10
    Forum Expert shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2003, 2010
    Posts
    40,678
    Thank you, pjoaquin, for stepping in. Jeff, his suggested change should work fine. Looking at it again, the formula could be simplified:

    =COUNTIF($T$16:$T16, "R") * COUNTIF($T16:$T$600, "R")

  11. #11
    Registered User
    Join Date
    08-23-2007
    Posts
    58
    Thanks, Paul, shg, for all the help!

    worked out great!

    Jeff

  12. #12
    Registered User
    Join Date
    08-23-2007
    Posts
    58
    Hello.

    A follow up to this quarry..

    I'm using this conditional format code (compliments of "shg")

    =COUNTIF($T$16:$T16, "R") * COUNTIF($T16:$T$600, "R")


    It works great!...However my worksheet has become very slow.. I have several such columns with this formula, albeit
    triggered by a different value : ie:


    =COUNTIF($AN$16:$AN16, "A") * COUNTIF($AN16:$AN$600, "A")

    =COUNTIF($AN$16:$AN16, "B") * COUNTIF($AN16:$AN$600, "B")

    =COUNTIF($AN$16:$AN16, "C") * COUNTIF($AN16:$AN$600, "C")

    =COUNTIF($AN$16:$AN16, "D") * COUNTIF($AN16:$AN$600, "D")






    Is there a way to incorporate this as a VBA macro. One that I can assign to
    a module and initiate via button assingment?

    ...I currently have these ranges as Named Ranges ie: "RangeA"(AD16:AD600), "RangeB" (AE16:AE600), etc.


    Thanks for any help..

    Jeff

+ Reply to Thread

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