Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2
Default define end column in a range

I would like to accomplish two things in vb code:
1) create a variable that defines the last column of a
given range (i.e. lastcol = ?).
2) Then use the variable as part of a selected range (i.e.
Range("A1:lastcol")

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 493
Default define end column in a range

One way, among many:

If the variable rng is set to your given range:

Dim lastCol as Integer
LastCol = rng(rng.Count).Column

To use (again, one among many):

Dim newRange As Range
Set newRange = Range("A1").Resize(1, lastCol)

or
Dim newRange As Range
Set newRange = Range(Cells(1, 1), Cells(1, lastCol))



In article ,
"Chris Perry" wrote:

I would like to accomplish two things in vb code:
1) create a variable that defines the last column of a
given range (i.e. lastcol = ?).
2) Then use the variable as part of a selected range (i.e.
Range("A1:lastcol")

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
Define Name range Gotroots Excel Discussion (Misc queries) 10 December 19th 09 11:30 AM
Define a range by searching for first and last? Gadget Excel Discussion (Misc queries) 2 May 23rd 09 12:10 AM
Define a range jlclyde Excel Discussion (Misc queries) 2 April 17th 08 08:26 PM
Define a range based on another named range Basil Excel Worksheet Functions 2 February 21st 05 01:47 PM
Define Range with an offset GregR Excel Discussion (Misc queries) 9 December 21st 04 07:22 AM


All times are GMT +1. The time now is 11:24 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"