VBA to capture selected range

brid

New Member
Joined
Jul 25, 2006
Messages
17
This is simple, but I am having trouble finding the answer in VBA Help than I would be asking it in this forum, so here goes:

The user highlights a range of cells, then runs my macro. The first thing my macro needs to do is to find the rows and columns that define the range that was selected. How do I do it?

ActiveWindow.RangeSelection gives me the range (e.g. $B$4:$G$8), but I want the rows and columns as integers and would prefer not to have to parse.

Thx, brid
 

Excel Facts

Which lookup functions find a value equal or greater than the lookup value?
MATCH uses -1 to find larger value (lookup table must be sorted ZA). XLOOKUP uses 1 to find values greater and does not need to be sorted.

Richard Schollar

MrExcel MVP
Joined
Apr 19, 2005
Messages
23,707
Hi Brid

I think you'll have to parse the result in one way or another. It will no doubt be easier to do so if you return an R1C1-style address reference:

Code:
Debug.Print Selection.Address(,,xlR1C1)

Best regards

Richard

PS as long as you know the address of the top left cell in the selection, then you can determine the rest from:

Code:
Debug.Print Selection.Rows.Count
Debug.Print Selection.Columns.Count
 

Forum statistics

Threads
1,136,589
Messages
5,676,679
Members
419,644
Latest member
KeelsM

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Top