ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Turning Tabs Colors on the input into a cell (https://www.excelbanter.com/excel-programming/358526-turning-tabs-colors-input-into-cell.html)

Jurrasicway

Turning Tabs Colors on the input into a cell
 
Can someone please help with this peice of code. I am trying to change the
tab color of the active sheet to either Red, Amber or Green based on the
input into cell I5 of my worksheet. Code as follows but it is not quite
right:

Private Sub iActiveCellI5_Change()
If ActiveCell.Range("I5") = "Green" Then
Sheets("1. Banking").Select
ActiveWorkbook.Sheets("1. Banking").Tab.ColorIndex = 10
Else
If ActiveCell.Range("I5") = "Amber" Then
ActiveWorkbook.Sheets("1. Banking").Tab.ColorIndex = 3
End If
If ActiveCell.Range("I5") = "Red" Then
ActiveWorkbook.Sheets("1. Banking").Tab.ColorIndex = 45
End If
End If
End Sub

Any help would be greatly appreciated....

Edwin Tam[_7_]

Turning Tabs Colors on the input into a cell
 
Your macro is basically correct. However, you should put the code into the
"Worksheet_Change" event of the worksheet which contains your "I5" cell.

I modified the code a bit. See below.

Private Sub Worksheet_Change(ByVal Target As Range)
With ThisWorkbook.Sheets("1. Banking").Tab
Select Case Range("I5")
Case "Green"
.ColorIndex = 10
Case "Amber"
.ColorIndex = 45
Case "Red"
.ColorIndex = 3
Case Else
'do nothing?
End Select
End With
End Sub

Regards,
Edwin Tam

http://www.vonixx.com


"Jurrasicway" wrote:

Can someone please help with this peice of code. I am trying to change the
tab color of the active sheet to either Red, Amber or Green based on the
input into cell I5 of my worksheet. Code as follows but it is not quite
right:

Private Sub iActiveCellI5_Change()
If ActiveCell.Range("I5") = "Green" Then
Sheets("1. Banking").Select
ActiveWorkbook.Sheets("1. Banking").Tab.ColorIndex = 10
Else
If ActiveCell.Range("I5") = "Amber" Then
ActiveWorkbook.Sheets("1. Banking").Tab.ColorIndex = 3
End If
If ActiveCell.Range("I5") = "Red" Then
ActiveWorkbook.Sheets("1. Banking").Tab.ColorIndex = 45
End If
End If
End Sub

Any help would be greatly appreciated....


Richard Buttrey

Turning Tabs Colors on the input into a cell
 
On Mon, 10 Apr 2006 12:31:02 -0700, Jurrasicway
wrote:

Can someone please help with this peice of code. I am trying to change the
tab color of the active sheet to either Red, Amber or Green based on the
input into cell I5 of my worksheet. Code as follows but it is not quite
right:

Private Sub iActiveCellI5_Change()
If ActiveCell.Range("I5") = "Green" Then
Sheets("1. Banking").Select
ActiveWorkbook.Sheets("1. Banking").Tab.ColorIndex = 10
Else
If ActiveCell.Range("I5") = "Amber" Then
ActiveWorkbook.Sheets("1. Banking").Tab.ColorIndex = 3
End If
If ActiveCell.Range("I5") = "Red" Then
ActiveWorkbook.Sheets("1. Banking").Tab.ColorIndex = 45
End If
End If
End Sub

Any help would be greatly appreciated....


I'd be inclined to name your input cell so that you can avoid having
to make it the active cell. In the procedure below I've assumed I5 is
named "input"

Private Sub iActiveCellI5_Change()

With Worksheets("1. Banking")
Select Case Range("input")
Case Is = "Green"
.Tab.ColorIndex = 10
Case Is = "Amber"
.Tab.ColorIndex = 3
Case Is = "Red"
. Tab.ColorIndex = 3
End Select
End With

End Sub

HTH
__
Richard Buttrey
Grappenhall, Cheshire, UK
__________________________

Jurrasicway

Turning Tabs Colors on the input into a cell
 
Thanks Edwin,

"Edwin Tam" wrote:

Your macro is basically correct. However, you should put the code into the
"Worksheet_Change" event of the worksheet which contains your "I5" cell.

I modified the code a bit. See below.

Private Sub Worksheet_Change(ByVal Target As Range)
With ThisWorkbook.Sheets("1. Banking").Tab
Select Case Range("I5")
Case "Green"
.ColorIndex = 10
Case "Amber"
.ColorIndex = 45
Case "Red"
.ColorIndex = 3
Case Else
'do nothing?
End Select
End With
End Sub

Regards,
Edwin Tam

http://www.vonixx.com


"Jurrasicway" wrote:

Can someone please help with this peice of code. I am trying to change the
tab color of the active sheet to either Red, Amber or Green based on the
input into cell I5 of my worksheet. Code as follows but it is not quite
right:

Private Sub iActiveCellI5_Change()
If ActiveCell.Range("I5") = "Green" Then
Sheets("1. Banking").Select
ActiveWorkbook.Sheets("1. Banking").Tab.ColorIndex = 10
Else
If ActiveCell.Range("I5") = "Amber" Then
ActiveWorkbook.Sheets("1. Banking").Tab.ColorIndex = 3
End If
If ActiveCell.Range("I5") = "Red" Then
ActiveWorkbook.Sheets("1. Banking").Tab.ColorIndex = 45
End If
End If
End Sub

Any help would be greatly appreciated....



All times are GMT +1. The time now is 02:05 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com