Macro for recalculation of range of cells in active sheet

lechev65

Board Regular
Joined
Mar 7, 2010
Messages
147
Hi guys,

I need to recalculate range of cells with RANDBETWEEN formula.
I assign the below macro to command button where I substitute
the "Range" with the range I need to recalculate only "D5:S19"
but it doesn't work.

Private Sub CommandButton1_Click()
If TypeName(Selection) = "Range" Then Selection.Calculate
End Sub

When I assign the macro for recalculation of the entire sheet,
it works.

Private Sub CommandButton2_Click()
ActiveSheet.Calculate
End Sub


Thank you in advance for you valuable advice!
 

Some videos you may like

Excel Facts

Ambidextrous Undo
Undo last command with Ctrl+Z or Alt+Backspace. If you use the Undo icon in the QAT, open the drop-down arrow to undo up to 100 steps.

AlphaFrog

MrExcel MVP
Joined
Sep 2, 2009
Messages
16,222
Code:
Private Sub CommandButton1_Click()
    Range("D5:S19").Calculate
End Sub
 

lechev65

Board Regular
Joined
Mar 7, 2010
Messages
147
Code:
Private Sub CommandButton1_Click()
    Range("D5:S19").Calculate
End Sub
Many thanks for the prompt reply. Unfortunately the macro recalculates also the other cells with RANDBETWEEN formulas outside the selected range "D5:S19"...?
 

Watch MrExcel Video

Forum statistics

Threads
1,090,508
Messages
5,414,967
Members
403,558
Latest member
Hardeni

This Week's Hot Topics

Top