Home |
Search |
Today's Posts |
#1
|
|||
|
|||
Changing the columns to copy
I am trying to write a macro that will copy 3 columns into a new sheet. Once
this is done and I have run the other part of my macro I want it to go back and copy another 3 columns. I always want to copy column "A" each time. The 1st time I want "A,B,C" then columns "A,D,E". "A,F,G" etc. Currently I have: Sheets("SBS Graphs - Main").Select Range("A:A, B:B, C:C").Select Range("C1").Activate Selection.Copy Sheets("Test").Select Range("A1").Select ActiveSheet.Paste <remaining macro which I have been copying. How do I get the macro so it changes the column reference for the last 2? Thanks |
#2
|
|||
|
|||
You could use a variable to select the columns, e.g.:
'==================== Dim ws1 As Worksheet Dim ws2 As Worksheet Dim i As Integer Set ws1 = Sheets("SBS Graphs - Main") Set ws2 = Sheets("Test") ws2.Cells.ClearContents For i = 1 To 10 Union(ws1.Cells(1, 1), ws1.Range(ws1.Cells(1, i * 2), _ ws1.Cells(1, i * 2 + 1))).EntireColumn.Copy _ Destination:=ws2.Cells(1, (i - 1) * 3 + 1) Next i '==================== fullers wrote: I am trying to write a macro that will copy 3 columns into a new sheet. Once this is done and I have run the other part of my macro I want it to go back and copy another 3 columns. I always want to copy column "A" each time. The 1st time I want "A,B,C" then columns "A,D,E". "A,F,G" etc. Currently I have: Sheets("SBS Graphs - Main").Select Range("A:A, B:B, C:C").Select Range("C1").Activate Selection.Copy Sheets("Test").Select Range("A1").Select ActiveSheet.Paste <remaining macro which I have been copying. How do I get the macro so it changes the column reference for the last 2? Thanks -- Debra Dalgleish Excel FAQ, Tips & Book List http://www.contextures.com/tiptech.html |
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|
Similar Threads | ||||
Thread | Forum | |||
reminder notifications in a column | Excel Discussion (Misc queries) | |||
columns changing to numbers | Excel Discussion (Misc queries) | |||
Unable to Copy COUNTA() with cell references | Excel Worksheet Functions | |||
copy COLUMN from 1 worksheet to another (in a different workbook) | Excel Discussion (Misc queries) | |||
Counting the Contents of Two Columns | Excel Discussion (Misc queries) |