Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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
like image 769
sdfg Avatar asked Sep 10 '10 17:09

sdfg


2 Answers

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

HTH!

like image 160
Dr. belisarius Avatar answered Nov 08 '22 07:11

Dr. belisarius


Sub macro1()
  MsgBox Selection.Address
End Sub

or

Sub macro1()
    Dim addr as String
    addr = Selection.Address
    msgbox addr

    ' Now, as we found the address, according to that... you can also do other operations

End Sub
like image 21
Ajitabh Ranjan Avatar answered Nov 08 '22 08:11

Ajitabh Ranjan