Microsoft Office Tutorials and References
In Depth Information
Working with Ranges
The Sub procedure that follows demonstrates how to pause a macro and let the user select a
range. The code then inserts a formula into each cell of the specified range.
Sub GetUserRange()
Dim UserRange As Range
Prompt = “Select a range for the random numbers.”
Title = “Select a range”
‘ Display the Input Box
On Error Resume Next
Set UserRange = Application.InputBox( _
Prompt:=Prompt, _
Title:=Title, _
Default:=ActiveCell.Address, _
Type:=8) ‘Range selection
On Error GoTo 0
‘ Was the Input Box canceled?
If UserRange Is Nothing Then
MsgBox “Canceled.”
Else
UserRange.Formula = “=RAND()”
End If
End Sub
The input box is shown in Figure 11-6.
Figure 11-6: Use an input box to pause a macro.
 
Search JabSto ::




Custom Search