Excel 2007macros获取选定的行

我想获得用户已经在Excel表中使用macrosselect的行。 我该怎么做?

我附上了一张图片。 我select了第3行。我想要在macros中获取所选的行。 如果用户select多行,我想要获取macros中的所有行。

在Excel工作表中选定的行

Selection将获得当前select的范围。

 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