excelvbaautomatic-properties

Assign macro to shape, stop automatic updating


In Excel, I have a dropdown list in cell C6. A user then inputs a numerical value into cell C10. I then have 4 dependent cells (dependent on cells C6, and the value inputted into cell C10), in C13, C17, C18 and C19. 2 of these cells (C17, C18) update according to the inputted value in C10 when a shape is pressed, however, the other 2 cells update automatically when you click off cell C10 because they use formulas instead. I am unable to provide detailed code as it is an internal project... but is there a way to add the formulas to the macro so that all 4 values only update when the button is pressed, rather than how it is now? Or even for all 4 to update when you click off C10 (then I can get rid of the shape). Any help would be appreciated.

Say I have removed the formulas from the cells, then using

Private Sub Worksheet_Change(ByVal Target As Range)
    If Application.Intersect(Target, Range("$C$6,K$12")) Then
        'Call button click sub code (update C17 and C18)
        'Update C13 and C19 with VBA code
    End If
End Sub

Please can you edit this so that you're giving an example... say I have my VBA code for C17 and C18 by

Sub ReadGraphData() 
... 
End Sub 

and the formulas for the cells are given by C13: C10*0.001/1.26 C19: GetRecentData() (this is a personally created function in another module) ... How would I form this?


Solution

  • Please follow these steps:

    All four cells (C13, C17, C18, and C19) will be automatically updated whenever there is a change made to cells C6 or C12.

    Private Sub Worksheet_Change(ByVal Target As Range)
        If Application.Intersect(Target, Range("$C$6,K$12")) Then
            'Call button click sub code (update C17 and C18)
            Call ReadGraphData
            'Update C13 and C19 with VBA code
            [C19] = GetRecentData()
            Range("C13").FormulaR1C1 = "=R[-3]C*0.001/1.26"
        End If
    End Sub