Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 23
Default Setting a Variable range in VBA

I'm trying to define a variable range based on the row before the last one
that contains data. Have tried a variety of methods, but so far none that
work. Due to methods used to load drop down controls the last row contains
<End; therefore, I need to use the row right above as the control for sorts,
etc. The Column Range is fixed so I've tried;

Range("B3:AE" & VARIABLE).Select

where the VARIABLE is the last row offset -1. The results always include
<End in the sort.

Any advice will be appreciated...
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,302
Default Setting a Variable range in VBA

Hi Hawk,

Perhaps your problem relates to the definition of the last row,

In any case the following works for me:

'=============
Public Sub Tester()
Dim rng As Range
Dim LastRow As Long

LastRow = Cells(Rows.Count, "B").End(xlUp).Row

Set rng = Range("B3:AE" & LastRow - 1)
rng.Select

End Sub
'<<=============


---
Regards,
Norman


"The Hawk" wrote in message
...
I'm trying to define a variable range based on the row before the last one
that contains data. Have tried a variety of methods, but so far none that
work. Due to methods used to load drop down controls the last row
contains
<End; therefore, I need to use the row right above as the control for
sorts,
etc. The Column Range is fixed so I've tried;

Range("B3:AE" & VARIABLE).Select

where the VARIABLE is the last row offset -1. The results always include
<End in the sort.

Any advice will be appreciated...



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 23
Default Setting a Variable range in VBA

Thanks Norman. You were right about the definition.

"Norman Jones" wrote:

Hi Hawk,

Perhaps your problem relates to the definition of the last row,

In any case the following works for me:

'=============
Public Sub Tester()
Dim rng As Range
Dim LastRow As Long

LastRow = Cells(Rows.Count, "B").End(xlUp).Row

Set rng = Range("B3:AE" & LastRow - 1)
rng.Select

End Sub
'<<=============


---
Regards,
Norman


"The Hawk" wrote in message
...
I'm trying to define a variable range based on the row before the last one
that contains data. Have tried a variety of methods, but so far none that
work. Due to methods used to load drop down controls the last row
contains
<End; therefore, I need to use the row right above as the control for
sorts,
etc. The Column Range is fixed so I've tried;

Range("B3:AE" & VARIABLE).Select

where the VARIABLE is the last row offset -1. The results always include
<End in the sort.

Any advice will be appreciated...




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


Similar Threads
Thread Thread Starter Forum Replies Last Post
Setting a range within a loop variable for copy/paste Craig[_24_] Excel Programming 3 December 21st 05 04:05 PM
Macro in VBA: Setting a variable print range HELP NEEDED!! Ron de Bruin Excel Programming 1 July 21st 04 05:45 PM
setting a range variable equal to the value of a string variable Pilgrim Excel Programming 2 July 1st 04 11:32 PM
Setting range value to a variable Todd Excel Programming 4 June 2nd 04 04:51 PM
Setting up a variable print range Gary[_5_] Excel Programming 5 July 31st 03 04:32 AM


All times are GMT +1. The time now is 05:43 PM.

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

About Us

"It's about Microsoft Excel"