pt966
09-27-2007, 06:40 AM
Hi - I am a "newbie" playing with a small VBA routine that I am trying to apply to an existing workbook for sorting out the annual leave allocation within our office.
The workbook is set up so that each staff member has their own calendar sheet.
Each sheet is then linked to twelve monthly sheets - change an entry on the individuals sheet and it changes to relevant months sheet.
What I have been doing "manually" up to now is then checking the monthly sheets and highlighting each changed cell according to its contents.
The sheets are also used for recording sickness and courses etc.
I have recently found out about Excel's "conditional formatting" but it doesn't give enough colour options.
I have seen a "post" (on this site) with a VBA routine for this style of formatting and also seen a "post" on another site with a similar, shorter, solution.
I have amended the "second" "posted" routine to reflect my usage and it works on one sheet of a new workbook when I enter the value directly on that sheet.
If I link the first sheet (formatted) to a second sheet (i.e. make the formatted cell "=sheet2!A1" for example) then the routine doesn't recognise that the character content of the formatted cell has changed (when a different character is entered into the linked cell on sheet 2).
Also, if I then enter the same VBA code onto another sheet in the same book - it doesn't work even if the characters are entered directly onto that sheet.
Please can you help me by explaining, in simple terms(?), how to get it to work, on all of the monthly sheets (called "Jan", "Feb", ..... "Dec"), so that a change to the individuals sheet (sheet1! for example) would be recognised on the monthly sheet ("Jan" for example) and its colour changed?
I have listed the VBA routine below:
Private Sub Worksheet_Change(ByVal Target As Range)
Dim icolor As Integer
If Not Intersect(Target, Range("D5:AH32")) Is Nothing Then
Select Case Target
Case "R"
icolor = 6
Case "A"
icolor = 12
Case "B"
icolor = 53
Case "C"
icolor = 15
Case "S"
icolor = 42
Case Else
' Whatever
End Select
Target.Interior.ColorIndex = icolor
End If
End Sub
For reference, R=Rota day off, A & B are different types of annual leave, C=Course leave and S=sick
The range (D5:AH32) is the area of the excel worksheet that I need to format.
"icolor" value sets the new colour for the cell that has changed.
Many thanks (in anticipation) for any assistance that you might be able to give me.
Peter
The workbook is set up so that each staff member has their own calendar sheet.
Each sheet is then linked to twelve monthly sheets - change an entry on the individuals sheet and it changes to relevant months sheet.
What I have been doing "manually" up to now is then checking the monthly sheets and highlighting each changed cell according to its contents.
The sheets are also used for recording sickness and courses etc.
I have recently found out about Excel's "conditional formatting" but it doesn't give enough colour options.
I have seen a "post" (on this site) with a VBA routine for this style of formatting and also seen a "post" on another site with a similar, shorter, solution.
I have amended the "second" "posted" routine to reflect my usage and it works on one sheet of a new workbook when I enter the value directly on that sheet.
If I link the first sheet (formatted) to a second sheet (i.e. make the formatted cell "=sheet2!A1" for example) then the routine doesn't recognise that the character content of the formatted cell has changed (when a different character is entered into the linked cell on sheet 2).
Also, if I then enter the same VBA code onto another sheet in the same book - it doesn't work even if the characters are entered directly onto that sheet.
Please can you help me by explaining, in simple terms(?), how to get it to work, on all of the monthly sheets (called "Jan", "Feb", ..... "Dec"), so that a change to the individuals sheet (sheet1! for example) would be recognised on the monthly sheet ("Jan" for example) and its colour changed?
I have listed the VBA routine below:
Private Sub Worksheet_Change(ByVal Target As Range)
Dim icolor As Integer
If Not Intersect(Target, Range("D5:AH32")) Is Nothing Then
Select Case Target
Case "R"
icolor = 6
Case "A"
icolor = 12
Case "B"
icolor = 53
Case "C"
icolor = 15
Case "S"
icolor = 42
Case Else
' Whatever
End Select
Target.Interior.ColorIndex = icolor
End If
End Sub
For reference, R=Rota day off, A & B are different types of annual leave, C=Course leave and S=sick
The range (D5:AH32) is the area of the excel worksheet that I need to format.
"icolor" value sets the new colour for the cell that has changed.
Many thanks (in anticipation) for any assistance that you might be able to give me.
Peter