Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 6
Default Reference a Column in Code

below is a put together of a sub that I am trying to
accomplish where I will look at the top cell in a column
and if it meets the criteria, then I want it to copy that
column onto another worksheet to the first open column but
not sure how to reference columns in the code. When I
leave it as below with Columns ("A:A") it works fine, but
I need ("A:A") to equal colnum or something like that, but
when I try
Columns ("colnum:colnum") it does not work and I have
tried it without the quotes as well. Any assistance would
be appreciated. What the real question is, is how to
reference a column in code, I can get it to work for Row,
column but not sure how to get it to work for the entire
column. Code below is a slopy example. Thanks in advance

Wally Steadman

Sub one()
dim colct as VARIANT
dim colnum as (INTEGER or VARIANT)
colct = 1

Columns("G:G").Select
Selection.copy
Sheets("Sheet2").Select
Columns("A:A").Select
ActiveSheet.Paste
End Sub
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 59
Default Reference a Column in Code

Wally,

just use a single integer as the columne reference. For
example, this routine looks at the first ten columns in
sheet 1. If the value in row 1 is greater than 3, it
copies the whole column into sheet 2, starting at A and
moving on one each time a column is copied.

Dim X as Integer
dim y as integer

Y = 1
For X = 1 to 10

If Cells(1,x).value 3 then
Columns(X).copy destintion:=sheets("Sheet2").cells(1,y)
y = y + 1
End IF

Next X


Cheers, Pete

-----Original Message-----
below is a put together of a sub that I am trying to
accomplish where I will look at the top cell in a column
and if it meets the criteria, then I want it to copy that
column onto another worksheet to the first open column

but
not sure how to reference columns in the code. When I
leave it as below with Columns ("A:A") it works fine, but
I need ("A:A") to equal colnum or something like that,

but
when I try
Columns ("colnum:colnum") it does not work and I have
tried it without the quotes as well. Any assistance

would
be appreciated. What the real question is, is how to
reference a column in code, I can get it to work for Row,
column but not sure how to get it to work for the entire
column. Code below is a slopy example. Thanks in advance

Wally Steadman

Sub one()
dim colct as VARIANT
dim colnum as (INTEGER or VARIANT)
colct = 1

Columns("G:G").Select
Selection.copy
Sheets("Sheet2").Select
Columns("A:A").Select
ActiveSheet.Paste
End Sub
.

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
Use text from a cell reference in vba code. JackyJ Excel Discussion (Misc queries) 1 October 4th 10 07:57 AM
Naming a reference table for use in a VBA Code CAT Excel Discussion (Misc queries) 4 October 2nd 08 01:36 PM
Row reference increment but preserve column reference Pwanda Excel Worksheet Functions 1 April 28th 05 01:12 PM
Macro to Reference Column Next to Current Reference dolphinv4 Excel Discussion (Misc queries) 2 April 11th 05 08:36 AM
Adding reference in code Andrew O'Brien Excel Programming 7 November 4th 03 09:43 PM


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