MWeber2222
New Member
Hi,
I developed the following macro(s) to run on a single worksheet whenever the user makes a change to specific fields. Now the user wants to have the macros run on multiple instances of the worksheet within the same workbook. Any idea how I need to modify the code in order to do this?
I have attached the file and code for your review. I appreciate any help that may be offered.
Thanks!
Mike W.
I developed the following macro(s) to run on a single worksheet whenever the user makes a change to specific fields. Now the user wants to have the macros run on multiple instances of the worksheet within the same workbook. Any idea how I need to modify the code in order to do this?
I have attached the file and code for your review. I appreciate any help that may be offered.
Thanks!
Mike W.
Code:
____________________________________________
Private Sub Worksheet_Change(ByVal Target As Range)
If Not Intersect(Target, Range("C7:C9")) Is Nothing Then
Call LightColors
Call LightColorsTotal
ElseIf Not Intersect(Target, Range("G7:G8")) Is Nothing Then
Call LightColorsDevice
Call LightColorsTotal
ElseIf Not Intersect(Target, Range("K7:K9")) Is Nothing Then
Call LightColorsAccount
Call LightColorsTotal
ElseIf Not Intersect(Target, Range("O7:O8")) Is Nothing Then
Call LightColorsFinancial
Call LightColorsTotal
End If
End Sub
____________________________________________
Sub LightColors()
Application.Volatile
'Unprotect sheet
ActiveSheet.Unprotect Password:="xpsibpt-2015-public"
Application.Calculation = xlCalculationAutomatic
ActiveSheet.Shapes("Rectangle1").Visible = False
ActiveSheet.Range("B18:C32").Borders.LineStyle = xlNone
ActiveSheet.Protect Password:="xpsibpt-2015-public"
' Client Light
Dim rng As Range
Dim ShapeName As String
Dim SHP As Shape
' Define shape and range information
ShapeName = "Oval 1"
Set rng = ThisWorkbook.Worksheets("Trainee Rating").Range("MergeRange1")
Set SHP = rng.Parent.Shapes(ShapeName)
' Assign shape colors
' Gray
If rng.Text = "#N/A" Then
SHP.Fill.ForeColor.RGB = RGB(217, 217, 217)
Exit Sub
End If
' Green
If rng.Value >= 80 Then
SHP.Fill.ForeColor.RGB = RGB(157, 207, 119)
End If
ActiveSheet.Unprotect Password:="xpsibpt-2015-public"
' Yellow
If rng.Value >= 55 And rng.Value < 80 Then
SHP.Fill.ForeColor.RGB = RGB(254, 225, 80)
'Note box
ActiveSheet.Shapes("Rectangle1").Visible = True
Range("B18:C32").BorderAround Weight:=xlThin
ActiveSheet.Range("B18:C32").Locked = False
Else
ActiveSheet.Range("B18:C32").Borders.LineStyle = xlNone
End If
' Red
If rng.Value < 55 And rng.Value > 0 Then
SHP.Fill.ForeColor.RGB = RGB(233, 126, 123)
'Note box
ActiveSheet.Shapes("Rectangle1").Visible = True
Range("B18:C32").BorderAround Weight:=xlThin
ActiveSheet.Range("B18:C32").Locked = False
End If
ActiveSheet.Protect Password:="xpsibpt-2015-public"
End Sub
____________________________________________
Sub LightColorsDevice()
Application.Volatile
'Unprotect sheet
ActiveSheet.Unprotect Password:="xpsibpt-2015-public"
Application.Calculation = xlCalculationAutomatic
ActiveSheet.Shapes("Rectangle2").Visible = False
ActiveSheet.Range("F18:G32").Borders.LineStyle = xlNone
ActiveSheet.Protect Password:="xpsibpt-2015-public"
' Client Light
Dim rng As Range
Dim ShapeName As String
Dim SHP As Shape
' Define shape and range information
ShapeName = "Oval 2"
Set rng = ThisWorkbook.Worksheets("Trainee Rating").Range("MergeRange2")
Set SHP = rng.Parent.Shapes(ShapeName)
' Assign shape colors
' Gray
If rng.Text = "#N/A" Then
SHP.Fill.ForeColor.RGB = RGB(217, 217, 217)
Exit Sub
End If
' Green
If rng.Value >= 80 Then
SHP.Fill.ForeColor.RGB = RGB(157, 207, 119)
End If
ActiveSheet.Unprotect Password:="xpsibpt-2015-public"
' Yellow
If rng.Value >= 55 And rng.Value < 80 Then
SHP.Fill.ForeColor.RGB = RGB(254, 225, 80)
'Note box
ActiveSheet.Shapes("Rectangle2").Visible = True
Range("F18:G32").BorderAround Weight:=xlThin
ActiveSheet.Range("F18:G32").Locked = False
Else
ActiveSheet.Range("F18:G32").Borders.LineStyle = xlNone
End If
' Red
If rng.Value < 55 And rng.Value > 0 Then
SHP.Fill.ForeColor.RGB = RGB(233, 126, 123)
'Note box
ActiveSheet.Shapes("Rectangle2").Visible = True
Range("F18:G32").BorderAround Weight:=xlThin
ActiveSheet.Range("F18:G32").Locked = False
End If
ActiveSheet.Protect Password:="xpsibpt-2015-public"
End Sub
____________________________________________
Sub LightColorsAccount()
Application.Volatile
'Unprotect sheet
ActiveSheet.Unprotect Password:="xpsibpt-2015-public"
Application.Calculation = xlCalculationAutomatic
ActiveSheet.Shapes("Rectangle3").Visible = False
ActiveSheet.Range("J18:K32").Borders.LineStyle = xlNone
ActiveSheet.Protect Password:="xpsibpt-2015-public"
' Client Light
Dim rng As Range
Dim ShapeName As String
Dim SHP As Shape
' Define shape and range information
ShapeName = "Oval 3"
Set rng = ThisWorkbook.Worksheets("Trainee Rating").Range("MergeRange3")
Set SHP = rng.Parent.Shapes(ShapeName)
' Assign shape colors
' Gray
If rng.Text = "#N/A" Then
SHP.Fill.ForeColor.RGB = RGB(217, 217, 217)
Exit Sub
End If
' Green
If rng.Value >= 80 Then
SHP.Fill.ForeColor.RGB = RGB(157, 207, 119)
End If
ActiveSheet.Unprotect Password:="xpsibpt-2015-public"
' Yellow
If rng.Value >= 55 And rng.Value < 80 Then
SHP.Fill.ForeColor.RGB = RGB(254, 225, 80)
'Note box
ActiveSheet.Shapes("Rectangle3").Visible = True
Range("J18:K32").BorderAround Weight:=xlThin
ActiveSheet.Range("J18:K32").Locked = False
Else
ActiveSheet.Range("J18:K32").Borders.LineStyle = xlNone
End If
' Red
If rng.Value < 55 And rng.Value > 0 Then
SHP.Fill.ForeColor.RGB = RGB(233, 126, 123)
'Note box
ActiveSheet.Shapes("Rectangle3").Visible = True
Range("J18:K32").BorderAround Weight:=xlThin
ActiveSheet.Range("J18:K32").Locked = False
End If
ActiveSheet.Protect Password:="xpsibpt-2015-public"
End Sub
____________________________________________
Sub LightColorsFinancial()
Application.Volatile
'Unprotect sheet
ActiveSheet.Unprotect Password:="xpsibpt-2015-public"
Application.Calculation = xlCalculationAutomatic
ActiveSheet.Shapes("Rectangle4").Visible = False
ActiveSheet.Range("N18:O32").Borders.LineStyle = xlNone
ActiveSheet.Protect Password:="xpsibpt-2015-public"
' Client Light
Dim rng As Range
Dim ShapeName As String
Dim ShapeName4 As String
Dim SHP As Shape
' Define shape and range information
ShapeName = "Oval 4"
Set rng = ThisWorkbook.Worksheets("Trainee Rating").Range("MergeRange4")
Set SHP = rng.Parent.Shapes(ShapeName)
' Assign shape colors
' Gray
If rng.Text = "#N/A" Then
SHP.Fill.ForeColor.RGB = RGB(217, 217, 217)
Exit Sub
End If
' Green
If rng.Value >= 80 Then
SHP.Fill.ForeColor.RGB = RGB(157, 207, 119)
End If
ActiveSheet.Unprotect Password:="xpsibpt-2015-public"
' Yellow
If rng.Value >= 55 And rng.Value < 80 Then
SHP.Fill.ForeColor.RGB = RGB(254, 225, 80)
'Note box
ActiveSheet.Shapes("Rectangle4").Visible = True
Range("N18:O32").BorderAround Weight:=xlThin
ActiveSheet.Range("N18:O32").Locked = False
Else
ActiveSheet.Range("N18:O32").Borders.LineStyle = xlNone
End If
' Red
If rng.Value < 55 And rng.Value > 0 Then
SHP.Fill.ForeColor.RGB = RGB(233, 126, 123)
'Note box
ActiveSheet.Shapes("Rectangle4").Visible = True
Range("N18:O32").BorderAround Weight:=xlThin
ActiveSheet.Range("N18:O32").Locked = False
End If
ActiveSheet.Protect Password:="xpsibpt-2015-public"
End Sub
____________________________________________
Sub LightColorsTotal()
Application.Calculation = xlCalculationAutomatic
Application.Volatile
' Client Light
Dim rng As Range
Dim ShapeName As String
Dim SHP As Shape
' Define shape and range information
ShapeName = "Oval 5"
Set rng = ThisWorkbook.Worksheets("Trainee Rating").Range("MergeRange5")
Set SHP = rng.Parent.Shapes(ShapeName)
' Assign shape colors
' Gray
If rng.Text = "#N/A" Then
SHP.Fill.ForeColor.RGB = RGB(217, 217, 217)
Exit Sub
End If
' Green
If rng.Value >= 80 Then
SHP.Fill.ForeColor.RGB = RGB(157, 207, 119)
End If
' Yellow
If rng.Value >= 55 And rng.Value < 80 Then
SHP.Fill.ForeColor.RGB = RGB(254, 225, 80)
End If
' Red
If rng.Value < 55 And rng.Value > 0 Then
SHP.Fill.ForeColor.RGB = RGB(233, 126, 123)
End If
End Sub
____________________________________________
Sub ResetSheet()
'Unprotect Data Sheet
ActiveSheet.Unprotect Password:="xpsibpt-2015-public"
' Clear PullDowns
Sheets("Trainee Rating").Range("C7:C9").ClearContents
Sheets("Trainee Rating").Range("G7:G8").ClearContents
Sheets("Trainee Rating").Range("K7:K9").ClearContents
Sheets("Trainee Rating").Range("O7:O8").ClearContents
' Clear Data
Sheets("Trainee Rating").Range("J3:K3").ClearContents
Sheets("Trainee Rating").Range("N3:O3").ClearContents
Sheets("Trainee Rating").Range("R3:S3").ClearContents
'Clear Notes
Sheets("Trainee Rating").Unprotect Password:="xpsibpt-2015-public"
Sheets("Trainee Rating").Range("B18:C32").ClearContents
Sheets("Trainee Rating").Range("F18:G32").ClearContents
Sheets("Trainee Rating").Range("J18:K32").ClearContents
Sheets("Trainee Rating").Range("N18:O32").ClearContents
'Protect Data Sheet
ActiveSheet.Range("B18:C32").Locked = True
ActiveSheet.Range("F18:G32").Locked = True
ActiveSheet.Range("J18:K32").Locked = True
ActiveSheet.Range("N18:O32").Locked = True
ActiveSheet.Protect Password:="xpsibpt-2015-public"
End Sub