PDA

View Full Version : [SOLVED:] How to assign a worksheet change codes to a button to refresh the values



anish.ms
12-28-2022, 11:10 AM
Dear Experts,

The values in columns 7 and 8 are based on a formula. Hence, the code doesn't work whenever there is a change in the value calculated by the formula. Is there any way to assign these 2 subs a button for a given range in addition to the worksheet change event?



Private Sub Worksheet_Change(ByVal Target As Range)
Dim rCell As Range
Dim iMax As Long
iMax = ActiveSheet.Cells(Rows.Count, 2).End(xlUp).Row

For Each rCell In Target.Cells
If (rCell.Column = 7 Or rCell.Column = 8 Or rCell.Column = 11) And (3 <= rCell.Row) And (rCell.Row <= iMax) Then
Application.EnableEvents = False
Application.ScreenUpdating = False
Application.Calculation = xlManual
Call Risk_Rating(rCell)
Call Audit_Plan(rCell)
Application.EnableEvents = True
Application.ScreenUpdating = True
Application.Calculation = xlAutomatic
End If
Next
End Sub

SamT
12-28-2022, 12:10 PM
Delete "Private" from Worksheet Event code declaration
Button Code:

Worksheet_Change Range("G:H")
End Sub

If you can't delete "Private", (I've never tried...) You might need an intermediary Sub for the Button(s) to call

Sub Intermediary(ByVal Target as Range)
Me.Worksheet_Change Target
End Sub

anish.ms
12-28-2022, 09:09 PM
Thanks Sam!
the first option is working