+ Reply to Thread
Results 1 to 10 of 10

VBA Code to change row color

  1. #1
    Forum Contributor
    Join Date
    04-05-2013
    Location
    CT
    MS-Off Ver
    Excel 2010
    Posts
    360

    VBA Code to change row color

    I would like a VBA code to change a row (from A to G) to a spacific color based on the text if column C17:C200.

    For example if the cell says "Concern" the row turns yellow.

    here is the code i'm using now. the problem is when i change the text in row C to anything, it turns the row to gray (15). none of the colors work?

    i cant use conditional formatting because i also like this sheet to a pie chart which changes colors based on the cell color.

    Please Login or Register  to view this content.
    Last edited by arlu1201; 04-05-2013 at 10:29 AM. Reason: Use code tags in future.

  2. #2
    Forum Contributor arlu1201's Avatar
    Join Date
    09-09-2011
    Location
    Bangalore, India
    MS-Off Ver
    Excel 2003 & 2007
    Posts
    19,167

    Re: VBA Code to change row color

    You have put this condition
    Please Login or Register  to view this content.
    so its turning the row grey.
    If I have helped, Don't forget to add to my reputation (click on the star below the post)
    Don't forget to mark threads as "Solved" (Thread Tools->Mark thread as Solved)
    Use code tags when posting your VBA code: [code] Your code here [/code]

  3. #3
    Forum Contributor
    Join Date
    04-05-2013
    Location
    CT
    MS-Off Ver
    Excel 2010
    Posts
    360

    Re: VBA Code to change row color

    when i delete that row the code doesnt do anything at all. (no color change). Im new to VBA

    Please Login or Register  to view this content.
    Last edited by arlu1201; 04-05-2013 at 10:46 AM.

  4. #4
    Forum Contributor arlu1201's Avatar
    Join Date
    09-09-2011
    Location
    Bangalore, India
    MS-Off Ver
    Excel 2003 & 2007
    Posts
    19,167

    Re: VBA Code to change row color

    I have added code tags to your 3rd post as i did to your 1st post. As per forum rule 3, you need to use them whenever you put any code in your post. Please add them in future. In order to put code tags, either type [CODE]Please [url=https://www.excelforum.com/login.php]Login or Register [/url] to view this content.[/CODE] at the end of it, OR you can highlight your code and click the # icon at the top of your post window.

  5. #5
    Forum Contributor arlu1201's Avatar
    Join Date
    09-09-2011
    Location
    Bangalore, India
    MS-Off Ver
    Excel 2003 & 2007
    Posts
    19,167

    Re: VBA Code to change row color

    You do not need to delete it. You had specified the condition that the row should be colored grey if anything "else" appears other than the conditions you have specified. Hence the row is grey.

    If you remove the condition it should leave the row with its default color (white).

  6. #6
    Forum Contributor
    Join Date
    04-05-2013
    Location
    CT
    MS-Off Ver
    Excel 2010
    Posts
    360

    Re: VBA Code to change row color

    Sorry for being slow on this.

    So what exactly should the code look like to get this working? If my last condition is set to color anything "else" gray, why doesnt it set the rows that say "Complete" green? basically none of the colors work except for that last condition?

    so here is the revised code so the cells dont turn gray....

    Please Login or Register  to view this content.

  7. #7
    Forum Contributor arlu1201's Avatar
    Join Date
    09-09-2011
    Location
    Bangalore, India
    MS-Off Ver
    Excel 2003 & 2007
    Posts
    19,167

    Re: VBA Code to change row color

    Can you attach a sample of the file you are using? (You can put dummy data in).

    To Attach a File:

    1. Click on Go Advanced
    2. In the frame Attach Files you will see the button Manage Attachments
    3. Click the button.
    4. A new window will open titled Manage Attachments - Excel Forum.
    5. Click the Browse... button to locate your file for uploading.
    6. This will open a new window File Upload.
    7. Once you have located the file to upload click the Open button. This window will close.
    8. You are now back in the Manage Attachments - Excel Forum window.
    9. Click the Upload button and wait until the file has uploaded.
    10. Close the window and then click Submit.

  8. #8
    Forum Contributor
    Join Date
    04-05-2013
    Location
    CT
    MS-Off Ver
    Excel 2010
    Posts
    360

    Re: VBA Code to change row color

    here it is i hope
    Attached Files Attached Files

  9. #9
    Forum Contributor
    Join Date
    04-05-2013
    Location
    CT
    MS-Off Ver
    Excel 2010
    Posts
    360

    Re: VBA Code to change row color

    i got it working by using the following code. Thanks for your help.

    Please Login or Register  to view this content.

  10. #10
    Forum Contributor arlu1201's Avatar
    Join Date
    09-09-2011
    Location
    Bangalore, India
    MS-Off Ver
    Excel 2003 & 2007
    Posts
    19,167

    Re: VBA Code to change row color

    Sorry i didnt get a chance to look at this sooner.

    In the code in post 9 you are looping through the rows multiple times for each condition, which is not a very efficient way to do it.

    The reason your code as not working was because your column had value "CONCERN" while your code had it as "Concern".

    Check the below code -
    Please Login or Register  to view this content.

+ 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