Copy Columns to other Sheet

bcschouten
08-07-2003, 08:11 AM
Hello,

I want to copy the columns of sheet1 to sheet3 in a different order.
I have made a table on sheet2 in wich order the columns have to be coppied. This is my code ( for 3 columns ):

Sub Button1()
Sheets("Sheet1").Select
Columns("B:B").Select <- I want B:B to be the variable placed in the table on sheet2
Selection.Copy
Sheets("Sheet3").Select
Columns("A:A").Select
ActiveSheet.Paste

Sheets("Sheet1").Select
Columns("A:A").Select
Selection.Copy
Sheets("Sheet").Select
Columns("B:B").Select
ActiveSheet.Paste

Sheets("Sheet1").Select
Columns("C:C").Select
Selection.Copy
Sheets("Sheet3").Select
Columns("C:C").Select
ActiveSheet.Paste
End Sub

Hope you guys can help me out.

Tnx

herilane
08-07-2003, 08:25 AM
What is your question / problem?

bcschouten
08-07-2003, 08:37 AM
I have a table on sheet 2 with how I want to copy the colums from sheet 1 to sheet 3. Like this:

Column On sheet 1 : Column On sheet 3
B : A
A : B
C : C

Now column B of sheet 1 is coppied to sheet 3, etc.

But I want to make the destination column variable. But I don't know how to change this sentence: Columns("B:B").Select in something that works. I have tried this:
Columns("Sheet(2).Cells(2,2):Sheet(2).Cells(2,2)").Select

Insomniac
08-07-2003, 12:17 PM
This should copy the specified columns of a table in Sheet2 assuming your table is in Columns A and B starting from A1.

Sub cpyColumns()
'assumes column references in Sheet2 format in cellA1 "B" & cellB1 "A"
'copies column combinations until a blank cell in sheet2 columnA is found
Dim cpy As String
Dim pst As String
Dim rw As Long

For rw = 1 To Sheet2.Range("A1").End(xlDown).Row
cpy = Sheet2.Cells(rw, 1)
pst = Sheet2.Cells(rw, 2)
Sheet1.Columns(cpy & ":" & cpy).Copy Sheet3.Columns(pst & ":" & pst)
Next
Application.CutCopyMode = False
End Sub

bcschouten
08-08-2003, 03:41 AM
Thanks. It Works !!!!

EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum