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!
 

AlphaFrog

MrExcel MVP
Joined
Sep 2, 2009
Messages
16,195
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"...?
 

Forum statistics

Threads
1,086,020
Messages
5,387,260
Members
402,054
Latest member
JHENGNDK

Some videos you may like

This Week's Hot Topics

Top