DanM
DanM

Reputation: 195

how to get user to input a range from a dialog box

so i need to get a range from the user, how is it possible to query the user to select a range, something like"

dim x as range
x = getrange("Select Range to Compare")
msgbox "The range selected is " & x

is there a way to do this?

Upvotes: 3

Views: 180

Answers (1)

Subodh Tiwari sktneer
Subodh Tiwari sktneer

Reputation: 9976

You may try something like this. Tweak it as per your requirement.

Sub AskUserToSelectARangeToWorkWith()
Dim Rng As Range
On Error Resume Next
Set Rng = Application.InputBox("Select a Range to compare.", "Select A Range!", Type:=8)
If Rng Is Nothing Then
    MsgBox "You didn't select a Range.", vbCritical, "No Range Selected!"
    Exit Sub
End If
MsgBox "The Range selected is " & Rng.Address(0, 0)
End Sub

Upvotes: 4

Related Questions