referencing current range of cells selected

T

Tom

Is there a way to reference the current cell range selected?

For example the following statement select the range A1:B3

Range("A1:B3").Select

However, if I select cells A3: B5 is there a command to set the selection in
VB to that range without specifically indicating the cells. So I highlight
cells A3:B5 then I would like to set that as the range selection and then
perform some actions on that range, then highlight another range of cells and
do the same set of actions.
 
J

JLGWhiz

When you do this:

Range("A1:B3").Select

You can then use:

Selection.Font.Bold = True

Generally speaking it is just as easy to use the range address
(Range("A1:B3")when referring to a range on a one shot basis. However, if
you are going to be referring to a specific range on a repetitive basis you
can either name the range, Insert>Name>Define, or Set the range to a
variable. To Set the variable:

Set myRange = ActiveSheet.Range("A1:B3")

Then you can just refer to myRange anywhere in the code and it will know
which specific set of cells you mean. For a single cell, you can always use
ActiveCell for the selected cell. If you have a cell selected and you want
to refer to the entire group of cells around the selected cell, you can use
ActiveCell.CurrentRegion.

All of this information is available in your VBA help files. Access the VB
editor and look up keywords "cell reference" then review the several topics
that the help menu displays.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top