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

Last used cell?
Press Ctrl+End to move to what Excel thinks is the last used cell.

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,497
Messages
5,414,891
Members
403,551
Latest member
benlinford

This Week's Hot Topics

Top