Question : Pass a selected range of cells as a paramter to a procedure

I have an Excel 2007 workbook that is large so have turned off auto- calc.  I have found VBA to calculate the worksheet when needed - that is, when the user hits the "cacl" button, the worksheet will calculate.  However, what if I need them to dynamically select only a range to caclulate?  In the HELP, to calculate a range suggested: A specified range:
                                  Worksheets(1).Rows(2).Calculate.  

But the range may change each time the user needs to view and test different results.  So, if the user selects D5:C25, how do I tell the command to replace Rows(2) with this range?

Answer : Pass a selected range of cells as a paramter to a procedure

Try this.
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
Option Explicit

Sub ProblemCode()
    Dim oRangeSelected As Range
    On Error Resume Next
    Set oRangeSelected = Application.InputBox("Please select a range of cells!", _
                                              "SelectARAnge Demo", Selection.Address, , , , , 8)
    If oRangeSelected Is Nothing Then
        MsgBox "It appears as if you pressed cancel!"
    Else
        MsgBox "You selected: " & oRangeSelected.Address(External:=True)
    End If
End Sub
Random Solutions  
 
programming4us programming4us