Referring to active range - should be easy

sykes

Well-known Member
Joined
May 1, 2002
Messages
1,885
Office Version
  1. 365
Platform
  1. Windows
You know when you get a complete brain failure...............

How do I refer to the active (selected) range in a sheet?

I want to press commandbutton1, and simply sum the cells in whatever the active range is - so if I've selected T4:T10, for example, then press the button, I get a messagebox with the sum of all the values in the selected range. Should be so easy, but I can't remember how to refer to the current selection.

something like:
Code:
dim cl as range
dim dbl as double

For each cl in activerange
      dbl = dbl + cl.value
next
msgbox "£" & dbl

Any ideas Folks?
 

Excel Facts

Format cells as date
Select range and press Ctrl+Shift+3 to format cells as date. (Shift 3 is the # sign which sort of looks like a small calendar).
Lovely job, thank you - and super quick as well!
 
Upvote 0

Forum statistics

Threads
1,224,502
Messages
6,179,126
Members
452,890
Latest member
Nikhil Ramesh

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