Excel 2007 macro get selected rows
excel, vba
Solution
`Selection` will get the current selected range.
Sub test()
Dim rng As Range
Set rng = Selection
'Will return address of selected range
MsgBox rng.Address
'will return row num
Msgbox rng.Row
'will give start row
MsgBox "Start Row : " & rng.Row
'will give end row
MsgBox "End Row : " & rng.Row + rng.Rows.Count - 1
End Sub
Problem
I would like to get the rows which are already selected by a user in an excel sheet using macros. How should I do that? I have attached an image. I have selected row number 3. I want to get that selected row in a macro. If the user selects more than one row, I want to get all those selected rows in the macro.