+ Reply to Thread
Results 1 to 12 of 12

Changing the sheet tab color based on the value of a cell

Hybrid View

  1. #1
    Registered User
    Join Date
    04-04-2014
    Location
    Iran
    MS-Off Ver
    Excel 2003
    Posts
    5

    Lightbulb Changing the sheet tab color based on the value of a cell

    Hi Guys,

    I am using excel 2010 and I want the color of my tabs to be changed to green if the value of cell M3 is 2.

    I have uploaded the file in here. Since I tried inserting the macros myself and it didn't work, it is appreciated if you place it in the my excel file and upload it again. Alternatively, you may email it to [email protected] as well.

    Thank you very much

  2. #2
    Forum Expert Solus Rankin's Avatar
    Join Date
    05-24-2013
    Location
    Hollywood, CA
    MS-Off Ver
    Win7 Office 2010 VS Express 2012
    Posts
    2,655

    re: Changing the sheet tab color based on the value of a cell

    Private Sub Workbook_SheetChange(ByVal Sh As Object, ByVal Target As Range)
    
    If Not Intersect(Target, Sh.Range("M3")) Is Nothing Then
        If Sh.Range("M3").Value = 2 Then
            Sh.Tab.Color = 5287936
        Else
            Sh.Tab.ColorIndex = -4142
        End If
    End If
    
    End Sub
    Place this in the workbook module. I can't place it for you because I can't download from the site you uploaded to.

    To attach a workbook here, click the 'Go Advanced' button below and use the paperclip in the toolbar to navigate to your document.
    Thanks,
    Solus


    Please remember the following:

    1. Use [code] code tags [/code]. It keeps posts clean, easy-to-read, and maintains VBA formatting.
    Highlight the code in your post and press the # button in the toolbar.
    2. Show appreciation to those who have helped you by clicking below their posts.
    3. If you are happy with a solution to your problem, mark the thread as [SOLVED] using the tools at the top.

    "Slow is smooth, smooth is fast."

  3. #3
    Registered User
    Join Date
    04-04-2014
    Location
    Iran
    MS-Off Ver
    Excel 2003
    Posts
    5

    re: Changing the sheet tab color based on the value of a cell

    Paymet Request List 1.xlsPaymet Request List 1.xls
    Quote Originally Posted by Solus Rankin View Post
    Private Sub Workbook_SheetChange(ByVal Sh As Object, ByVal Target As Range)
    
    If Not Intersect(Target, Sh.Range("M3")) Is Nothing Then
        If Sh.Range("M3").Value = 2 Then
            Sh.Tab.Color = 5287936
        Else
            Sh.Tab.ColorIndex = -4142
        End If
    End If
    
    End Sub
    Place this in the workbook module. I can't place it for you because I can't download from the site you uploaded to.

    To attach a workbook here, click the 'Go Advanced' button below and use the paperclip in the toolbar to navigate to your document.
    It doesn't work...I attached it as instructed...can you please place it in my excel file?

    Thx

  4. #4
    Forum Contributor
    Join Date
    03-04-2014
    Location
    Canada Eh
    MS-Off Ver
    Excel 2010
    Posts
    199

    re: Changing the sheet tab color based on the value of a cell

    Perhaps the following is hat you need:
    Sub SetSheetColour()
        Dim sht As Worksheet
        
        For Each sht In Sheets
            If sht.Range("M3").Value = 2 Then
                With sht.Tab
                    .Color = 5296274
                End With
            End If
        Next sht
    End Sub
    Click the * to give Rep to a post you like.

  5. #5
    Registered User
    Join Date
    04-04-2014
    Location
    Iran
    MS-Off Ver
    Excel 2003
    Posts
    5

    re: Changing the sheet tab color based on the value of a cell

    Quote Originally Posted by Mad-Mizer View Post
    Perhaps the following is hat you need:
    Sub SetSheetColour()
        Dim sht As Worksheet
        
        For Each sht In Sheets
            If sht.Range("M3").Value = 2 Then
                With sht.Tab
                    .Color = 5296274
                End With
            End If
        Next sht
    End Sub
    Thank you. It somehow works. But the problem is that all tabs just turn to green and their color doesn't change based on the value of cell M3!

  6. #6
    Forum Contributor
    Join Date
    03-04-2014
    Location
    Canada Eh
    MS-Off Ver
    Excel 2010
    Posts
    199

    re: Changing the sheet tab color based on the value of a cell

    Quote Originally Posted by Matb12 View Post
    Thank you. It somehow works. But the problem is that all tabs just turn to green and their color doesn't change based on the value of cell M3!
    I don't see how that's possible unless every sheet's M3 value = 2. I've run and re-run that in my workbook and it performs exactly how it should.

    Interesting.

  7. #7
    Forum Contributor
    Join Date
    03-04-2014
    Location
    Canada Eh
    MS-Off Ver
    Excel 2010
    Posts
    199

    re: Changing the sheet tab color based on the value of a cell

    Perhaps you should upload your workbook to this site, I cannot access the other one due to company restrictions.

  8. #8
    Registered User
    Join Date
    04-04-2014
    Location
    Iran
    MS-Off Ver
    Excel 2003
    Posts
    5

    re: Changing the sheet tab color based on the value of a cell

    Quote Originally Posted by Mad-Mizer View Post
    Perhaps you should upload your workbook to this site, I cannot access the other one due to company restrictions.
    Sure. You can download it from here. I am also attaching it to this post.

    It is appreciated if you place it in it and send it back.

    Thank you
    Attached Files Attached Files

  9. #9
    Forum Expert Solus Rankin's Avatar
    Join Date
    05-24-2013
    Location
    Hollywood, CA
    MS-Off Ver
    Win7 Office 2010 VS Express 2012
    Posts
    2,655

    re: Changing the sheet tab color based on the value of a cell

    Solus Edit.xls Perhaps.

  10. #10
    Forum Contributor
    Join Date
    03-04-2014
    Location
    Canada Eh
    MS-Off Ver
    Excel 2010
    Posts
    199

    re: Changing the sheet tab color based on the value of a cell

    Solus looks to have provided a working solution. Nice too.

  11. #11
    Registered User
    Join Date
    04-04-2014
    Location
    Iran
    MS-Off Ver
    Excel 2003
    Posts
    5

    re: Changing the sheet tab color based on the value of a cell

    I don't really know what's wrong, I have the same issue with the file that Solus posted. Mostly they are just green and don't change. Sometimes, only 1 tab turn to green and other tabs stay as they are!! I tried on both Excel 2007 on Windows XP and Excel 2010 on Windows 7 and the result was the same!

    I am uploading 2 screen shots.

    Excel 2.jpgExcel.jpg

  12. #12
    Forum Contributor
    Join Date
    03-04-2014
    Location
    Canada Eh
    MS-Off Ver
    Excel 2010
    Posts
    199

    re: Changing the sheet tab color based on the value of a cell

    Hi Matb12, I've looked at the workbook you've provided and all the sheets, at M3 = 2, which is your criteria for the tab colours being green. If I change the value at M3 to any other number the tab colour does not change to green.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. [SOLVED] Changing tab color based on cell value
    By taab0412 in forum Excel Programming / VBA / Macros
    Replies: 12
    Last Post: 01-30-2015, 01:17 PM
  2. [SOLVED] Changing fill color of shapes based on changing cell value
    By Stefan1983 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 11-25-2012, 10:33 AM
  3. Changing tab color based on cell value
    By PrizeGotti in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 11-22-2012, 07:29 AM
  4. Changing cell color based on value
    By smraines in forum Excel General
    Replies: 6
    Last Post: 12-30-2009, 07:39 PM
  5. changing cell color based on changing values
    By tvonbehren in forum Excel General
    Replies: 2
    Last Post: 09-16-2009, 12:33 PM

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