Search code examples
vbaexcelexcel-2007excel-2003

Excel VBA get range of user selected range by mouse


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

Solution

  • Sub macro1()
      MsgBox Selection.Address(ReferenceStyle:=xlA1, _
                               RowAbsolute:=False, ColumnAbsolute:=False)
    End Sub
    

    HTH!