+ Reply to Thread
Results 1 to 11 of 11

Cell Shading Macro Depending on Text

  1. #1
    Registered User
    Join Date
    01-10-2008
    Posts
    44

    Cell Shading Macro Depending on Text

    Hi there.

    I will have a spreadsheet similar to the image provided. Basically, I need the macro to go row by row down column I. If the cell in column I contains the word "Tech" I need the cells from column B to P to be shaded color1; if it contains "Update," color 2; if the cell is blank; leave the cell as is. Once the macro has done this, it will continue to the next row and to the same check.

    The number of rows in the spreadsheet will change on a day-to-day basis depending on the data that's pulled, but the columns should remain the same.

    So I think I have the shading part. This is what I have so far. I'm not sure if this is the most efficient way of coding it, but it kinda works. I guess another problem would be if in the future the column with this info (column I) changes and shifts.


    Please Login or Register  to view this content.

    I've been trying to figure something out, but I haven't been able to wrap my brain on how to do this.

    Thanks to all for any help you can provide.
    Attached Files Attached Files

  2. #2
    Forum Expert
    Join Date
    01-15-2007
    Location
    Brisbane, Australia
    MS-Off Ver
    2007
    Posts
    6,591
    Hi

    Try this

    Please Login or Register  to view this content.
    rylo

  3. #3
    Valued Forum Contributor Shijesh Kumar's Avatar
    Join Date
    05-26-2008
    Location
    Bangalore / India
    MS-Off Ver
    2000
    Posts
    717
    Hi.

    Try this code, it should work.

    I have made the assumption that column "A" will definitely contain some value so the macros will do its work until it encounter a blank in column "A"


    Please Login or Register  to view this content.

  4. #4
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,259
    Hello BluTalon,

    This version automatically "reads" the size of the your array using the first cell ($A$3) as a reference. It allows you to use more colors easily later on.
    Please Login or Register  to view this content.
    Sincerely,
    Leith Ross

  5. #5
    Registered User
    Join Date
    01-10-2008
    Posts
    44

    Red face

    oops. I'm sorry. Both seem to work, but I forgot that it also has a header row that automatically gets created when the spread sheet is exported.

    So, the header should not be edited, but it does contain "Tech" in one of the cells. This of course kinda screws up the way the macro formats the cells as the header turns a different color. Is there a way we can have it start below the header?

    Thanks and sorry again
    Attached Files Attached Files

  6. #6
    Forum Guru
    Join Date
    08-15-2004
    Location
    Tokyo, Japan
    MS-Off Ver
    2013 O.365
    Posts
    22,834
    Please Login or Register  to view this content.

  7. #7
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,259
    Hello BluTalon,

    To skip the header (1st row in the array), The "For R" loop needs to start at 2. I have made the change already. You can also change the column to check by changing the variable "C".
    Please Login or Register  to view this content.
    Sincerely,
    Leith Ross

  8. #8
    Forum Expert royUK's Avatar
    Join Date
    11-18-2003
    Location
    Derbyshire,UK
    MS-Off Ver
    Xp; 2007; 2010
    Posts
    26,200
    Why not use Conditional Formatting?

    See

    http://www.excel-it.com/excel_condit...formatting.htm
    Last edited by royUK; 05-31-2008 at 05:57 AM.
    Hope that helps.

    RoyUK
    --------
    For Excel Tips & Solutions, free examples and tutorials why not check out my web site

    Free DataBaseForm example

  9. #9
    Valued Forum Contributor Shijesh Kumar's Avatar
    Join Date
    05-26-2008
    Location
    Bangalore / India
    MS-Off Ver
    2000
    Posts
    717
    opps...

    It totally slipped out of my mind...


    Yes we can use conditional formating...

    That would be easy as well to use

  10. #10
    Registered User
    Join Date
    01-10-2008
    Posts
    44
    The thing is that the file is exported as a *.tab originally. I then go ahead and have it saved as an *.xls. Also, a new *.tab file is created at least once a day.

    I didn't think I could use conditional formatting in this situation without having to enter all the criteria into each new file each time it was exported. Is this right?

  11. #11
    Registered User
    Join Date
    01-10-2008
    Posts
    44
    Just wanted to give a quick thanks for your help! The macro works great.

+ 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