Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 542
Default Select column in VB based on variable

Hi all,

I would like my code to select a column (or range of columns) based on a
variable passed from another subroutine, but I'm not sure how to do it.

Example 1:
I would like to select the columns starting at column 2 (B) up to column
ColCount (my variable). So if ColCount=6, the macro would select columns B
through F

Example 2:
I would like the macro to select column ColCount+1 (So if ColCount = 6,
column G should be selected)

Example 3:
I would like the macro to select columns ColCount+3 and ColCount+4 (So if
ColCount = 6, columns I and J should be selected).

Many thanks,
James
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,058
Default Select column in VB based on variable

For your first example:

Sub dural()
colcnt = 6
Range(Cells(1, 2), Cells(1, colcnt)).EntireColumn.Select
End Sub

--
Gary''s Student - gsnu200806


"James" wrote:

Hi all,

I would like my code to select a column (or range of columns) based on a
variable passed from another subroutine, but I'm not sure how to do it.

Example 1:
I would like to select the columns starting at column 2 (B) up to column
ColCount (my variable). So if ColCount=6, the macro would select columns B
through F

Example 2:
I would like the macro to select column ColCount+1 (So if ColCount = 6,
column G should be selected)

Example 3:
I would like the macro to select columns ColCount+3 and ColCount+4 (So if
ColCount = 6, columns I and J should be selected).

Many thanks,
James

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 542
Default Select column in VB based on variable

Thanks Gary :)

This, combined with selection.offset has given me what I need.

James.

"Gary''s Student" wrote:

For your first example:

Sub dural()
colcnt = 6
Range(Cells(1, 2), Cells(1, colcnt)).EntireColumn.Select
End Sub

--
Gary''s Student - gsnu200806


"James" wrote:

Hi all,

I would like my code to select a column (or range of columns) based on a
variable passed from another subroutine, but I'm not sure how to do it.

Example 1:
I would like to select the columns starting at column 2 (B) up to column
ColCount (my variable). So if ColCount=6, the macro would select columns B
through F

Example 2:
I would like the macro to select column ColCount+1 (So if ColCount = 6,
column G should be selected)

Example 3:
I would like the macro to select columns ColCount+3 and ColCount+4 (So if
ColCount = 6, columns I and J should be selected).

Many thanks,
James

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
I am trying to select a new cell whose row address is based on a variable rub Excel Programming 4 November 29th 06 03:49 AM
How do I select a cell based on the Column name Teresa K. Excel Programming 3 November 28th 06 11:02 PM
Select a column based on a index VH Excel Programming 5 March 6th 06 09:40 AM
Sum cells based on a row variable and seperate column variable CheeseHeadTransplant Excel Worksheet Functions 10 September 23rd 05 06:59 PM
Select Cell based on Variable address achidsey Excel Programming 2 September 17th 05 06:47 PM


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