+ Reply to Thread
Results 1 to 5 of 5

autoset cell fill colour

  1. #1
    Registered User
    Join Date
    01-12-2007
    Posts
    3

    autoset cell fill colour

    Hello all

    i've got an excel (2003) worksheet with data pulling from an SQL database. in one of the columns (D), the cells can only have 1 of 4 numerical values (1, 2, 3, 301).

    when the data is refreshed, i want the cells in this column ONLY (column D) to change to a set colour depending on this numerical value.
    so eg if the value in D1 is "1" the cell should be red, if in D2 its "301", the cell goes green etc.

    I've tried some vb to do this, but it seems to consider values in all cells in the whole sheet(eg if there's a "3" in cell A7, it changes colour), and change colours of every cell, but i only want it to consider one column, with 4 values, and only fill the cells in that 1 column

    any help would be great

  2. #2
    Forum Contributor
    Join Date
    03-14-2006
    Location
    Pakistan
    Posts
    1,791

    Lightbulb

    Quote Originally Posted by andr3w266
    Hello all

    i've got an excel (2003) worksheet with data pulling from an SQL database. in one of the columns (D), the cells can only have 1 of 4 numerical values (1, 2, 3, 301).

    when the data is refreshed, i want the cells in this column ONLY (column D) to change to a set colour depending on this numerical value.
    so eg if the value in D1 is "1" the cell should be red, if in D2 its "301", the cell goes green etc.

    I've tried some vb to do this, but it seems to consider values in all cells in the whole sheet(eg if there's a "3" in cell A7, it changes colour), and change colours of every cell, but i only want it to consider one column, with 4 values, and only fill the cells in that 1 column

    any help would be great
    using Conditional Formatting will solve your problem

    try this link
    http://www.contextures.com/xlCondFormat01.html

    Conditional Formatting allow three conditions, however you can use any default colour as fourth option.

  3. #3
    Registered User
    Join Date
    01-12-2007
    Posts
    3
    thanks for the reply, i apprecite it.
    And it is a correct answer to my question.
    However, if i were to get more than 4 values (ie 1 default and 3 conditional) this wouldnt work, which is why i was trying to achieve this through VB rather than the conditional formatting options

  4. #4
    Forum Contributor
    Join Date
    03-14-2006
    Location
    Pakistan
    Posts
    1,791

    Lightbulb

    Quote Originally Posted by andr3w266
    thanks for the reply, i apprecite it.
    And it is a correct answer to my question.
    However, if i were to get more than 4 values (ie 1 default and 3 conditional) this wouldnt work, which is why i was trying to achieve this through VB rather than the conditional formatting options
    ok try this link

    http://www.ozgrid.com/VBA/excel-cond...ting-limit.htm

  5. #5
    Registered User
    Join Date
    01-12-2007
    Posts
    3
    ok thats almost what i was looking for. It works great if i manually add data to the cells . however, as the data if have is pulled from SQL, i have a button to refresh the data and pull in new info, and when i do that it errors in that new section of VB?

+ 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