ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   define end column in a range (https://www.excelbanter.com/excel-programming/278514-define-end-column-range.html)

Chris Perry

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")


J.E. McGimpsey

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")



All times are GMT +1. The time now is 11:55 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
ExcelBanter.com