Excel VBA get range of user selected range by mouse

sdfg picture sdfg · Sep 10, 2010 · Viewed 86.9k times · Source

This is not the usedrange issue.
For example in Excel user selects a range (possibly empty) using mouse, let's say B4:C12

And let's say after this without deselecting the range user presses the macro, and macro should tell B4:C12.

Can anyone show example?

The macro should be something along the lines of the following:

Sub showrng()
    MsgBox SelectedRange.Address(ReferenceStyle:=xlA1)
End Sub

Answer

Dr. belisarius picture Dr. belisarius · Sep 10, 2010
Sub macro1()
  MsgBox Selection.Address(ReferenceStyle:=xlA1, _
                           RowAbsolute:=False, ColumnAbsolute:=False)
End Sub

HTH!