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

Add Bullets to Range
Select range. Press Ctrl+1. On Number tab, choose Custom. Type Alt+7 then space then @ sign (using 7 on numeric keypad)
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
 
Upvote 0

Forum statistics

Threads
1,214,827
Messages
6,121,821
Members
449,049
Latest member
cybersurfer5000

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
Back
Top