+ Reply to Thread
Results 1 to 6 of 6

tab color

  1. #1
    briank
    Guest

    tab color

    I would like to alter the color of the tab based upon a value in an array of
    cells. In my example if the range is A1:A50 and just one cell has a number in
    it then this will cause the tab to change color. Here is some code that I
    found but cannot get it to work. Any suggestions?
    i.e.
    Private Sub Workbook_SheetChange(ByVal Sh As Object, ByVal Target As Range)
    If Target.Address = "$A$1..$A$50" Then
    If Target.Value>0 Then Sh.Tab.ColorIndex = 3
    End If
    End Sub

  2. #2
    Rob van Gelder
    Guest

    Re: tab color

    Right-click the Tab, View Code, Paste this code

    Private Sub Worksheet_Change(ByVal Target As Range)
    If Application.WorksheetFunction.CountA(Range("A1:A50")) = 1 Then
    Target.Parent.Tab.ColorIndex = 3
    Else
    Target.Parent.Tab.ColorIndex = 5
    End If
    End Sub


    --
    Rob van Gelder - http://www.vangelder.co.nz/excel


    "briank" <briank@discussions.microsoft.com> wrote in message
    news:ABCD25DF-6CF2-4499-8E3C-3A424BA56D51@microsoft.com...
    >I would like to alter the color of the tab based upon a value in an array
    >of
    > cells. In my example if the range is A1:A50 and just one cell has a number
    > in
    > it then this will cause the tab to change color. Here is some code that I
    > found but cannot get it to work. Any suggestions?
    > i.e.
    > Private Sub Workbook_SheetChange(ByVal Sh As Object, ByVal Target As
    > Range)
    > If Target.Address = "$A$1..$A$50" Then
    > If Target.Value>0 Then Sh.Tab.ColorIndex = 3
    > End If
    > End Sub




  3. #3
    briank
    Guest

    Re: tab color

    Thank you. It works gr8!

    "Rob van Gelder" wrote:

    > Right-click the Tab, View Code, Paste this code
    >
    > Private Sub Worksheet_Change(ByVal Target As Range)
    > If Application.WorksheetFunction.CountA(Range("A1:A50")) = 1 Then
    > Target.Parent.Tab.ColorIndex = 3
    > Else
    > Target.Parent.Tab.ColorIndex = 5
    > End If
    > End Sub
    >
    >
    > --
    > Rob van Gelder - http://www.vangelder.co.nz/excel
    >
    >
    > "briank" <briank@discussions.microsoft.com> wrote in message
    > news:ABCD25DF-6CF2-4499-8E3C-3A424BA56D51@microsoft.com...
    > >I would like to alter the color of the tab based upon a value in an array
    > >of
    > > cells. In my example if the range is A1:A50 and just one cell has a number
    > > in
    > > it then this will cause the tab to change color. Here is some code that I
    > > found but cannot get it to work. Any suggestions?
    > > i.e.
    > > Private Sub Workbook_SheetChange(ByVal Sh As Object, ByVal Target As
    > > Range)
    > > If Target.Address = "$A$1..$A$50" Then
    > > If Target.Value>0 Then Sh.Tab.ColorIndex = 3
    > > End If
    > > End Sub

    >
    >
    >


  4. #4
    briank
    Guest

    Re: tab color

    Follow Up: If I change the spreadsheet to elimate data in the cell range
    A1..A50, the tab still stays the same color. Is there a "refresh" command
    that I can add?

    "Rob van Gelder" wrote:

    > Right-click the Tab, View Code, Paste this code
    >
    > Private Sub Worksheet_Change(ByVal Target As Range)
    > If Application.WorksheetFunction.CountA(Range("A1:A50")) = 1 Then
    > Target.Parent.Tab.ColorIndex = 3
    > Else
    > Target.Parent.Tab.ColorIndex = 5
    > End If
    > End Sub
    >
    >
    > --
    > Rob van Gelder - http://www.vangelder.co.nz/excel
    >
    >
    > "briank" <briank@discussions.microsoft.com> wrote in message
    > news:ABCD25DF-6CF2-4499-8E3C-3A424BA56D51@microsoft.com...
    > >I would like to alter the color of the tab based upon a value in an array
    > >of
    > > cells. In my example if the range is A1:A50 and just one cell has a number
    > > in
    > > it then this will cause the tab to change color. Here is some code that I
    > > found but cannot get it to work. Any suggestions?
    > > i.e.
    > > Private Sub Workbook_SheetChange(ByVal Sh As Object, ByVal Target As
    > > Range)
    > > If Target.Address = "$A$1..$A$50" Then
    > > If Target.Value>0 Then Sh.Tab.ColorIndex = 3
    > > End If
    > > End Sub

    >
    >
    >


  5. #5
    Rob van Gelder
    Guest

    Re: tab color

    The code works as so:
    Whenever the worksheet changes, it counts the number of entries in A1:A50
    If it counts 1 then color is 3 otherwise the color is 5

    To see whether the code is running or not try this code:

    Private Sub Worksheet_Change(ByVal Target As Range)
    If Application.WorksheetFunction.CountA(Range("A1:A50")) = 1 Then
    MsgBox "Triggered 1"
    ' Target.Parent.Tab.ColorIndex = 3
    Else
    MsgBox "Triggered not 1"
    ' Target.Parent.Tab.ColorIndex = 5
    End If
    End Sub


    --
    Rob van Gelder - http://www.vangelder.co.nz/excel


    "briank" <briank@discussions.microsoft.com> wrote in message
    news:0919E2CF-BDDE-435F-A69C-D9B2042C9A12@microsoft.com...
    > Follow Up: If I change the spreadsheet to elimate data in the cell range
    > A1..A50, the tab still stays the same color. Is there a "refresh" command
    > that I can add?
    >
    > "Rob van Gelder" wrote:
    >
    >> Right-click the Tab, View Code, Paste this code
    >>
    >> Private Sub Worksheet_Change(ByVal Target As Range)
    >> If Application.WorksheetFunction.CountA(Range("A1:A50")) = 1 Then
    >> Target.Parent.Tab.ColorIndex = 3
    >> Else
    >> Target.Parent.Tab.ColorIndex = 5
    >> End If
    >> End Sub
    >>
    >>
    >> --
    >> Rob van Gelder - http://www.vangelder.co.nz/excel
    >>
    >>
    >> "briank" <briank@discussions.microsoft.com> wrote in message
    >> news:ABCD25DF-6CF2-4499-8E3C-3A424BA56D51@microsoft.com...
    >> >I would like to alter the color of the tab based upon a value in an
    >> >array
    >> >of
    >> > cells. In my example if the range is A1:A50 and just one cell has a
    >> > number
    >> > in
    >> > it then this will cause the tab to change color. Here is some code
    >> > that I
    >> > found but cannot get it to work. Any suggestions?
    >> > i.e.
    >> > Private Sub Workbook_SheetChange(ByVal Sh As Object, ByVal Target As
    >> > Range)
    >> > If Target.Address = "$A$1..$A$50" Then
    >> > If Target.Value>0 Then Sh.Tab.ColorIndex = 3
    >> > End If
    >> > End Sub

    >>
    >>
    >>




  6. #6
    Forum Contributor
    Join Date
    11-29-2003
    Posts
    1,203
    Try this:

    Private Sub Workbook_SheetChange(ByVal Sh As Object, ByVal Target As Range)

    If Application.WorksheetFunction.Sum(Sh.Range("A1:A50")) > 0 Then Sh.Tab.ColorIndex = 3

    End Sub

    - Pete

+ 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