Select column in VB based on variable

J

James

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
 
G

Gary''s Student

For your first example:

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

James

Thanks Gary :)

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

James.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top