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 Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

EXCEL VBA use of range( 1

Status
Not open for further replies.

ryno525

MIS
Aug 1, 2005
3
0
0
US
Is there an easier way to write this:

dim lastcell as range
Set lastcell = ActiveCell.Offset(-1, 7) 'happens at somepoint in the program

Range("b4:" & lastcell.Address(RowAbsolute:=False, ColumnAbsolute:=False)).Select



how about this:

Range(ActiveCell.Address(RowAbsolute:=False, ColumnAbsolute:=False) & ":" & ActiveCell.Offset(0, 5).Address(RowAbsolute:=False, ColumnAbsolute:=False)).Select
 


Hi,
Code:
    Set lastcell = ActiveCell.Offset(-1, 7)  'happens at somepoint in the program

    Range([b4], lastcell).Select

    Range(ActiveCell, ActiveCell.Offset(0, 5)).Select



Skip,
[sub]
[glasses] [red]Be Advised![/red] The Vinyards of Texas have produced a wine with diuretic dimishment and urethric relief...
Pinot More![tongue][/sub]
 

The three code snippets above all produce different results.

It's not clear what you need to have happen, but here is a slightly simpler way to do the same thing as your first code snippet
Code:
Range("B4", ActiveCell.Offset(-1, 7)).Select
 
Or if there is some other code between the two lines shown, then something like this:
Code:
:
:
Set RememberMe = ActiveCell
:
:
Range("B4", RememberMe.Offset(-1, 7)).Select
:
:
 
Or, since you already have
Code:
Set lastcell = ActiveCell.Offset(-1, 7)
Then you could just do this:
Code:
:
:
Range("B4", lastcell).Select
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top