Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Range Selection Using Offset.

Status
Not open for further replies.

mcmccompguru

Technical User
Apr 11, 2003
5
US
I want to select a range using the offset method. I have a cell activated, and I need to select two ranges from that cell. This all needs to be relative because the active cell will likely never be the same cell twice. Say the active cell is A1. Well, I need a section of code using the offset method to set A1:A10 as Range1, and then, using the same active cell, I need another range as A13:16, Range2. Again, I need to use Offset, or something to keep the references relative to the active cell and assign two ranges from there. Thanks in advance for the help.
 
Assuming that the activecell remains the same throughout then use this code for the 1st range:
Code:
  Range(ActiveCell, ActiveCell.Offset(10, 0)).Select
and this code for the 2nd range:
Code:
  Range(ActiveCell.Offset(13, 0), ActiveCell.Offset(16, 0)).Select

Hope this helps!

Clive [infinity]
Ex nihilo, nihil fit (Out of nothing, nothing comes)
 
.Offset is zero-based, so the code you need is
[blue]
Code:
  Range(ActiveCell, ActiveCell.Offset(9, 0)).Select
[/color]

and
[blue]
Code:
  Range(ActiveCell.Offset(12, 0), ActiveCell.Offset(15, 0)).Select
[/color]

Alternatively, some people have difficulty with-based references so you may be more comfortable with using .Cells instead of .Offset like this:
[blue]
Code:
  With ActiveCell
    Range(.Cells(1, 1), .Cells(10, 1)).Select
  End With
[/color]

and
[blue]
Code:
  With ActiveCell
    Range(.Cells(13, 1), .Cells(16, 1)).Select
  End With
[/color]



 
Thanks for the help. I had already caught the zero base error, thanks though. The alternative method was helpful to know, also. Thanks for the help!!!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top