Results 1 to 2 of 2

Modify Current VBA Cell Background Color Code

Threaded View

  1. #1
    Forum Contributor
    Join Date
    04-20-2011
    Location
    New York, New York
    MS-Off Ver
    Excel 2010
    Posts
    160

    Modify Current VBA Cell Background Color Code

    Hi,

    My current code changes the cell background color of all cells in Column A based on their value. I’ve attached the Excel Workbook (PivotTableReport) to this post. I want to modify this code so it meets the description below:

    I have three pivot fields in my pivot table found on worksheet (Current Macro). The first pivot field is found in Cell A9 by the name of “Type” and what I would like the new Macro to do is change the cell background color of the cell that contains the value "Team Red” to Red and all the cells (A21) right under “Team Red” to Red that are associated to the value of “Team Red” (take a look at worksheet “After New Macro Visual” for a visual of what this would look like). The new Macro would then proceed to do the same for the value “People” and “M&A” with their respective colors. Again, the worksheet “After New Macro Visual” will give you a good visual of what I am looking for.

    Current Code:

    Sub ChangeCellColor()
    Dim cell As Range
    For Each cell In Range("A:A")
    If cell.Value = "Team Red" Then
    cell.Interior.ColorIndex = 3
    ElseIf cell.Value = "M&A" Then
    cell.Interior.ColorIndex = 14
    ElseIf cell.Value = "People" Then
    cell.Interior.ColorIndex = 18
    End If
    Next
    End Sub
    Attached Files Attached Files
    Last edited by boldcode; 08-10-2011 at 08:29 AM. Reason: Solved by Marcol. Thanks!

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