+ Reply to Thread
Results 1 to 12 of 12

Conditional formatting tab colour based on cell range value

  1. #1
    Registered User
    Join Date
    10-06-2017
    Location
    Perth
    MS-Off Ver
    2016
    Posts
    8

    Conditional formatting tab colour based on cell range value

    Hi all!

    I should start out by clarifying, I have no programming experience with vba code. I require some assistance with a code for changing the colour of a sheet tab based on a particular number appearing in a range of cells.

    I have attached an example to help with explaining what I am after.

    The scenario is I have a cell range (C2:C16) that may or may not contain a value. If a cell in that range doesn't contain a value then no action is required, if it contains a value then I need to confirm if the corresponding cell in that row in range A2:A16 contains text or not. I have a formula I am using in range E2:E16 =IF(ISBLANK(C2),0,IF(AND(C2>0,A2<>""),1,2)) to return a 0,1,2 value to satisfy 3 different criteria. I then require a vba code that will change the colour of the sheet tab red if a "2" is returnerd in any cell in range E2:E16.

    I tried using this vba code to no avail (it is in my excel sheet example)
    Please Login or Register  to view this content.

    ANy help with this would be greatly appreciated.
    Attached Files Attached Files

  2. #2
    Registered User
    Join Date
    07-20-2018
    Location
    Quezon City, Philippines
    MS-Off Ver
    Excel 2013
    Posts
    84

    Re: Conditional formatting tab colour based on cell range value

    change the code to the following:
    the color code for red is 3

    Please Login or Register  to view this content.

  3. #3
    Forum Guru
    Join Date
    08-15-2004
    Location
    Tokyo, Japan
    MS-Off Ver
    2013 O.365
    Posts
    22,653

    Re: Conditional formatting tab colour based on cell range value

    brettosmith,
    Change event should be controlled to restrict the range in order to prevent unnecessary execution.
    This runs only if any one cell in A2:A16 or C2:C16 is changed, otherwise it ignores.
    Please Login or Register  to view this content.

  4. #4
    Registered User
    Join Date
    10-06-2017
    Location
    Perth
    MS-Off Ver
    2016
    Posts
    8

    Re: Conditional formatting tab colour based on cell range value

    Hi jindon,

    Thanks for the response.

    If I was now to implement that into another "worksheet change" routine on that sheet, how would i go about it?

    Below is my actual code that it needs to be implemented with:

    Please Login or Register  to view this content.

  5. #5
    Forum Guru
    Join Date
    08-15-2004
    Location
    Tokyo, Japan
    MS-Off Ver
    2013 O.365
    Posts
    22,653

    Re: Conditional formatting tab colour based on cell range value

    Perhaps
    Please Login or Register  to view this content.
    Edit: code
    Last edited by jindon; 09-12-2018 at 12:26 AM. Reason: Fixed a typo

  6. #6
    Registered User
    Join Date
    10-06-2017
    Location
    Perth
    MS-Off Ver
    2016
    Posts
    8

    Re: Conditional formatting tab colour based on cell range value

    Thanks jindon but I am getting a run-time error 1004, so when i chose to "debug" it highlights "Me.Tab.Color = vbRed"

  7. #7
    Forum Guru
    Join Date
    08-15-2004
    Location
    Tokyo, Japan
    MS-Off Ver
    2013 O.365
    Posts
    22,653

    Re: Conditional formatting tab colour based on cell range value

    See the attached.
    Attached Files Attached Files

  8. #8
    Registered User
    Join Date
    10-06-2017
    Location
    Perth
    MS-Off Ver
    2016
    Posts
    8

    Re: Conditional formatting tab colour based on cell range value

    It works fine on the test sheet but I am still getting a run-time error 1004 application-defined or object-defined error in my worksheet i require it for.

    I am 99% sure it is because my workbook is protected and doesn't allow modifications to the structure - is there a way to allow this in the code?

  9. #9
    Forum Guru
    Join Date
    08-15-2004
    Location
    Tokyo, Japan
    MS-Off Ver
    2013 O.365
    Posts
    22,653

    Re: Conditional formatting tab colour based on cell range value

    Can not replicate the issue here...

    It should work regardless of the workbook is protected or not.

  10. #10
    Registered User
    Join Date
    10-06-2017
    Location
    Perth
    MS-Off Ver
    2016
    Posts
    8

    Re: Conditional formatting tab colour based on cell range value

    jindon,

    try the attached two examples. Both are protected workbooks with no password. Run-time error occurs whilst workbook is protected. It works fine if you unprotect workbook.

    The "Template" Example is an actual worksheet from my workbook I am trying to get it working in. This is the best way to give you an idea of what I am working with.
    Attached Files Attached Files

  11. #11
    Forum Guru
    Join Date
    08-15-2004
    Location
    Tokyo, Japan
    MS-Off Ver
    2013 O.365
    Posts
    22,653

    Re: Conditional formatting tab colour based on cell range value

    Ok, then try add 2 lines
    Please Login or Register  to view this content.

  12. #12
    Registered User
    Join Date
    10-06-2017
    Location
    Perth
    MS-Off Ver
    2016
    Posts
    8

    Re: Conditional formatting tab colour based on cell range value

    Thanks for your help jindon.

    Much appreciated.

+ 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. Conditional Formatting - Cell colour based on date
    By HiYoJoe in forum Excel Formulas & Functions
    Replies: 8
    Last Post: 05-08-2017, 05:07 AM
  2. Replies: 6
    Last Post: 04-11-2016, 09:48 AM
  3. [SOLVED] Conditional Formatting - How to colour code based on range
    By ijb89 in forum Excel General
    Replies: 1
    Last Post: 02-03-2016, 10:11 AM
  4. Replies: 2
    Last Post: 05-12-2015, 04:39 PM
  5. [SOLVED] Partial conditional formatting based on the colour of a cell
    By ello2001 in forum Excel Formulas & Functions
    Replies: 3
    Last Post: 07-07-2014, 08:17 AM
  6. conditional formatting based on cell colour
    By nervous_pilchard in forum Excel General
    Replies: 0
    Last Post: 07-12-2011, 05:29 AM
  7. Colour Fill cell range in (Conditional formatting XL2007)
    By airbus319uk in forum Excel Formulas & Functions
    Replies: 9
    Last Post: 10-27-2007, 06:34 AM

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