Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.worksheet.functions
Tom from Ga
 
Posts: n/a
Default Using variables as first and last cells in range statement

How do you specify the 'RANGE(a:b).SELECT' statment using only
variables. I keep getting syntax errors when I attempt the following:


Dim endcell As String
endcell = Range("D65535").End(xlUp).Row
Dim firstcell As String
firstcell = Range(FinalRow - 4).Select

Range(firstcell:endcell).Select

  #2   Report Post  
Posted to microsoft.public.excel.worksheet.functions
just_jon
 
Posts: n/a
Default Using variables as first and last cells in range statement

A couple of ways below. Keep in mind that you do not need Select
statements to do most actions ...

Sub fooL()
Dim EndCell As Long
EndCell = Cells(Rows.Count, "D").End(xlUp).Row
Range("D" & FirstCell & ":D" & EndCell - 4).Select
End Sub

Sub fooR()
Dim EndCell As Range
Set EndCell = Cells(Rows.Count, "D").End(xlUp)
Range(EndCell.Offset(-4, 0), EndCell).Select
End Sub

  #3   Report Post  
Posted to microsoft.public.excel.worksheet.functions
Tom from Ga
 
Posts: n/a
Default Using variables as first and last cells in range statement

It seems to work. Thanks for your help. I'm learning by the trial
and error method. This is my first google group question and I'm
impressed by the quick response.

Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT +1. The time now is 02:34 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"