Consulting

Results 1 to 3 of 3

Thread: How to assign a worksheet change codes to a button to refresh the values

  1. #1
    VBAX Mentor
    Joined
    Nov 2020
    Location
    Cochin, Kerala
    Posts
    314
    Location

    How to assign a worksheet change codes to a button to refresh the values

    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

  2. #2
    Moderator VBAX Sage SamT's Avatar
    Joined
    Oct 2006
    Location
    Near Columbia
    Posts
    7,814
    Location
    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
    I expect the student to do their homework and find all the errrors I leeve in.


    Please take the time to read the Forum FAQ

  3. #3
    VBAX Mentor
    Joined
    Nov 2020
    Location
    Cochin, Kerala
    Posts
    314
    Location
    Thanks Sam!
    the first option is working

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •