ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Referring to a user-selected range (https://www.excelbanter.com/excel-programming/288129-referring-user-selected-range.html)

James Mc

Referring to a user-selected range
 
Can anyone advise how I can refer to a range in a spreadsheet that has
been selected by the user? Late in the macro, I need to loop through
all the cells in a range that the user selected earlier, and perform
an operation on each of them that depends on its location within the
range, but I can't figure out how to identify the range.

Thanks

James McIntosh
Australia

Rob van Gelder[_4_]

Referring to a user-selected range
 
James,

Sub testit()
Dim rng As Range

If TypeOf Selection Is Range Then
For Each rng In Selection
Debug.Print rng.Address
Next
End If
End Sub


Rob

"James Mc" wrote in message
om...
Can anyone advise how I can refer to a range in a spreadsheet that has
been selected by the user? Late in the macro, I need to loop through
all the cells in a range that the user selected earlier, and perform
an operation on each of them that depends on its location within the
range, but I can't figure out how to identify the range.

Thanks

James McIntosh
Australia




James McIntosh

Referring to a user-selected range
 

Rob,
Thanks for the code, I'll try it

James



*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!


All times are GMT +1. The time now is 09:45 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com