View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.programming
Rick Rothstein Rick Rothstein is offline
external usenet poster
 
Posts: 5,934
Default Select range of cells

To answer your question, this code will select from Row 2 down to the last
used row in the ActiveCell's column...

ACcolumn = ActiveCell.Column
Range(Cells(2, ACcolumn ), Cells(Rows.Count, ACcolumn ).End(xlUp)).Select

However, given your stated goals, you should know you don't need to first
select a range to do something to it... you can work directly with the
range. Perhaps this previous posting of mine (a response to another person
using Select/Selection type constructions) will be of some help to you in
your future programming...

Whenever you see code constructed like this...

Range("A1").Select
Selection.<whatever

you can almost always do this instead...

Range("A1").<whatever

In your particular case, you have this...

Range("C2:C8193").Select 'select cells to export
For Each r In Selection.Rows

which, using the above concept, can be reduced to this...

For Each r In Range("C2:C8193").Rows

Notice, all I have done is replace Selection with the range you Select(ed)
in the previous statement and eliminate the process of doing any
Select(ion)s. Stated another way, the Selection produced from
Range(...).Select is a range and, of course, Range(...) is a range... and,
in fact, they are the same range, so it doesn't matter which one you use.
The added benefit of not selecting ranges first is your active cell does not
change.

--
Rick (MVP - Excel)


"Alex" wrote in message
...
Can you please tell me how to select cells in row 2 through the last
active
cell in the active column. For example, if my cursor is in a cell in
column
J, I'd like cells J2:last active cell to be selected so that I can do some
find and replace, copy, etc on those cells. I'm having a hard time
getting
the J2. Thank you so much.