macro to have user select a range

longhornfan

New Member
Joined
Dec 16, 2011
Messages
4
I am in need to have an application.inbox prompt a user to enable the user to click a particular cell. From there i need the address of the cell as well as the sheet.

Code:
Dim MyRange As Range
Set MyRange = Application.InputBox("Select the range to process", Type:=8)

If Not MyRange Is Nothing Then
MsgBox MyRange.Parent.Name
     
    Else: Exit Sub
    End If

If the user presses cancel, exit sub would need to be there.
If the user presses the x, exit sub would need to be there.

I hope my ask is coming across clearly. i need be able to prompt a user to select the sheet they want to see and capture that sheet name for future use.:eek:
 

Excel Facts

Highlight Duplicates
Home, Conditional Formatting, Highlight Cells, Duplicate records, OK to add pink formatting to any duplicates in selected range.
Try:
Code:
Sub Test()
Dim MyRange As Range
On Error GoTo ExSub
Set MyRange = Application.InputBox("Select the range to process", Type:=8)
MsgBox MyRange.Parent.Name
ExSub:
End Sub
 
Upvote 0
Try...

Code:
[font=Courier New][color=darkblue]Option[/color] [color=darkblue]Explicit[/color]

[color=darkblue]Sub[/color] test()

    [color=darkblue]Dim[/color] MyRange [color=darkblue]As[/color] Range
    
    [color=darkblue]On[/color] [color=darkblue]Error[/color] [color=darkblue]Resume[/color] [color=darkblue]Next[/color]
    [color=darkblue]Set[/color] MyRange = Application.InputBox("Select the range to process.", Type:=8)
    [color=darkblue]On[/color] [color=darkblue]Error[/color] [color=darkblue]GoTo[/color] 0
    
    [color=darkblue]If[/color] MyRange [color=darkblue]Is[/color] [color=darkblue]Nothing[/color] [color=darkblue]Then[/color] [color=darkblue]Exit[/color] [color=darkblue]Sub[/color]
    
    MsgBox MyRange.Parent.Name
    
[color=darkblue]End[/color] [color=darkblue]Sub[/color]
[/font]
 
Upvote 0
Code:
    Dim MyRange As Range
    On Error Resume Next
    Set MyRange = Application.InputBox("Select the range to process", Type:=8)
    On Error GoTo 0
    If MyRange Is Nothing Then Exit Sub
    
    MsgBox MyRange.Parent.Name & vbCr & MyRange.Address
 
Upvote 0
Code:
    Dim MyRange As Range
    On Error Resume Next
    Set MyRange = Application.InputBox("Select the range to process", Type:=8)
    On Error GoTo 0
    If MyRange Is Nothing Then Exit Sub
 
    MsgBox MyRange.Parent.Name & vbCr & MyRange.Address

Worked. I took out the address part and did a set ws = MyRange.Parent.Name

Problem solved.
 
Upvote 0

Forum statistics

Threads
1,215,005
Messages
6,122,661
Members
449,091
Latest member
peppernaut

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top