Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 13
Default use a variable to set a range

How do I perform this:

'Obtain last column that contains data
lastCol = ActiveSheet.UsedRange.Column - 1 +
ActiveSheet.UsedRange.Columns.Count

'Convert to Alpha
(code omitted for brievity)

'Define the Column in the range based on the previous check
Range(lastCol:lastCol).Insert Shift:=xlToLeft

Thanks.
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 9,101
Default use a variable to set a range

With ActiveSheet
Set LastCell = .Cells.SpecialCells(xlCellTypeLastCell)
LastCell.EntireColumn.Insert Shift:=xlToLeft
End With

"Excel_VBA_Newb" wrote:

How do I perform this:

'Obtain last column that contains data
lastCol = ActiveSheet.UsedRange.Column - 1 +
ActiveSheet.UsedRange.Columns.Count

'Convert to Alpha
(code omitted for brievity)

'Define the Column in the range based on the previous check
Range(lastCol:lastCol).Insert Shift:=xlToLeft

Thanks.

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 13
Default use a variable to set a range

Thanks, Joel. However, I don't think I was very clear in my needs.

The problem I'm running into, is the column that i need to load into the
Range is dynamic. Sometime's it might be column C other times it might be
column G, etc.

So, I need to know how to load the range based on a variable. Let's throw
the insert out of the equation (I think that is confusing things). I need to
check for the last column then load a range based on last column - 1.

So, how do I load a range based on the variable.

Range("C:C") will give me the entire column "C"
How can I select a range based on the variable: Range(variable:variable)

Thanks!




"Joel" wrote:

With ActiveSheet
Set LastCell = .Cells.SpecialCells(xlCellTypeLastCell)
LastCell.EntireColumn.Insert Shift:=xlToLeft
End With

"Excel_VBA_Newb" wrote:

How do I perform this:

'Obtain last column that contains data
lastCol = ActiveSheet.UsedRange.Column - 1 +
ActiveSheet.UsedRange.Columns.Count

'Convert to Alpha
(code omitted for brievity)

'Define the Column in the range based on the previous check
Range(lastCol:lastCol).Insert Shift:=xlToLeft

Thanks.

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 9,101
Default use a variable to set a range

This is dynamic.
SpecialCells(xlCellTypeLastCell)


"Excel_VBA_Newb" wrote:

Thanks, Joel. However, I don't think I was very clear in my needs.

The problem I'm running into, is the column that i need to load into the
Range is dynamic. Sometime's it might be column C other times it might be
column G, etc.

So, I need to know how to load the range based on a variable. Let's throw
the insert out of the equation (I think that is confusing things). I need to
check for the last column then load a range based on last column - 1.

So, how do I load a range based on the variable.

Range("C:C") will give me the entire column "C"
How can I select a range based on the variable: Range(variable:variable)

Thanks!




"Joel" wrote:

With ActiveSheet
Set LastCell = .Cells.SpecialCells(xlCellTypeLastCell)
LastCell.EntireColumn.Insert Shift:=xlToLeft
End With

"Excel_VBA_Newb" wrote:

How do I perform this:

'Obtain last column that contains data
lastCol = ActiveSheet.UsedRange.Column - 1 +
ActiveSheet.UsedRange.Columns.Count

'Convert to Alpha
(code omitted for brievity)

'Define the Column in the range based on the previous check
Range(lastCol:lastCol).Insert Shift:=xlToLeft

Thanks.

  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 82
Default use a variable to set a range

There's no need to convert to the letter.

If you have the column number you could just use it.

ColNum = 3 ' column 3 is column C

Columns(ColNum).Interior.Color = vbRed


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
Range to VLOOKUP as a Variable (range in another file) LuisE Excel Programming 3 December 2nd 07 03:22 PM
select range and put range address in variable [email protected] Excel Programming 2 January 25th 06 01:28 AM
Macro to copy a specified range to a variable range SWT Excel Programming 4 October 21st 05 08:24 PM
setting a range variable equal to the value of a string variable Pilgrim Excel Programming 2 July 1st 04 11:32 PM
Problem trying to us a range variable as an array variable TBA[_2_] Excel Programming 4 September 27th 03 02:56 PM


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