PAX dbrw formula overwrite value with vba

Post Reply
monkey97
Posts: 16
Joined: Thu May 18, 2023 10:48 am
OLAP Product: tm1
Version: 10.1.10000.26473
Excel Version: 365

PAX dbrw formula overwrite value with vba

Post by monkey97 »

Hey!

How can i use vba code to override the DBRW formulas? No matter how i try the DBRW formulas remain, they are not overwritten with the value. Overall, I would like to see the snapshot function in vba code form.

Image

Thanks.
User avatar
WilliamSmith
Posts: 40
Joined: Tue Dec 13, 2022 8:54 pm
OLAP Product: TM1 / PA / PAx / PAW
Version: TM1 11
Excel Version: 365

Re: PAX dbrw formula overwrite value with vba

Post by WilliamSmith »

Hi my friend, I hope you are having a nice day.

Try this

Code: Select all

dim cell as range
set cell = ActiveCell 'ActiveCell, for each, etc.

Application.EnableEvents = False
cell.Formula = cell.Value 'or .Value2
Application.EnableEvents = True
It will prevent ExcelDNA batch recalculation (e.g. RECALC_XXXX) from triggering.
User avatar
WilliamSmith
Posts: 40
Joined: Tue Dec 13, 2022 8:54 pm
OLAP Product: TM1 / PA / PAx / PAW
Version: TM1 11
Excel Version: 365

Re: PAX dbrw formula overwrite value with vba

Post by WilliamSmith »

Also, you may find this helpful...

Trigger batch recalculation of TM1 formulas on a range, or worksheet. Useful for force re-calc in automated scripts:

Code: Select all

Sub ReCalcRng(rng As Range)

    calc = Application.Calculation
        
    Application.EnableEvents = False
    Application.Calculation = xlCalculationAutomatic
    Application.EnableEvents = True
    
    rng.Dirty
    
    Application.Calculation = calc

End Sub

Sub ReCalcWS(Optional ws)
    
    If IsMissing(ws) Then
    
        Set ws = ActiveSheet
    
    End If
    
    calc = Application.Calculation
        
    Application.EnableEvents = False
    Application.Calculation = xlCalculationAutomatic
    Application.EnableEvents = True
    
    ws.Cells.Dirty
    
    Application.Calculation = calc
    
End Sub
monkey97
Posts: 16
Joined: Thu May 18, 2023 10:48 am
OLAP Product: tm1
Version: 10.1.10000.26473
Excel Version: 365

Re: PAX dbrw formula overwrite value with vba

Post by monkey97 »

Thank you so much.
The solution was to turn Application.EnableEvents on and off.
Post Reply