VBA to copy data into Columns

ScottEmberson

New Member
Joined
Jul 31, 2014
Messages
12
Hi All

I currently have the code below that copy's data down in rows one after another, but I really want this to now go via columns now and not rows.

Can anyone help?

Thanks

Code:
    Sheets("Pivot_Table_Non_Closed_Area").Range("D12:D21").Copy    'Pastes the data from the sheet above in the next avaliable row.
    Sheets("Tracking_Table_Non_Closed_Area").Cells(Row.Count, "C").End(xlToLeft).Offset(1). _
    PasteSpecial Paste:=xlPasteValues, _
    Operation:=xlNone, SkipBlanks:=False, Transpose:=False
    Sheets("TC_Count_Tracking_Table").Select
    n = Cells(Column.Count, "B").End(xlUp).Row
    Range(n & "1") = Date
    Range(n & "B") = Time
 

Excel Facts

Best way to learn Power Query?
Read M is for (Data) Monkey book by Ken Puls and Miguel Escobar. It is the complete guide to Power Query.
I am a bit confused on where you are placing the item copied. In your code, n appears to return an integer of the last cell, but it appears like you're using it to identify the column of where you are placing the data.

This is what I would use to identify R (last used row) or C (last used Column):
Code:
R = Cells(Rows.Count, 3).End(xlUp).Row  'find last row in 3rd column (C)
    'Note:can replace 3 with "C" and yield same results
    
C = Cells(1, Columns.Count).End(xlToLeft).Column 'find last column in row1

As far as taking a column of data and copying to a row on a different worksheet, try out WorksheetFunction.Transpose:

Code:
Dim wsTarg As Worksheet
Dim wsDest As Worksheet
Set wsTarg = Sheets("Pivot_Table_Non_Closed_Area")
Set wsDest = Sheets("Tracking_Table_Non_Closed_Area")
With wsDest
    R = .Cells(.Rows.Count, "A").End(xlUp).Row  'first blank row in col A
    .Range("A" & R & ":J" & R) = WorksheetFunction.Transpose(wsTarg.Range("D12:D21"))
End With
 
Upvote 0
Hi Sorry I didn't make it clearer, I want to copy a column of data on worksheet 1 into another worksheet, but every time the macro copy's it I want to to move to the next column along. Is that still possible? I have tried your code you suggested put it just places it into rows rather than columns and it doesn't go down a new row/column each time the code is run.

Data to Copy = E09 to E109
Sheet to have coped data entered into would be start in D9 and continue up the columns

Thanks again
 
Upvote 0
That makes more sense! Try:
Code:
Dim wsTarg As Worksheet
Dim wsDest As Worksheet
Dim C As Integer
Set wsTarg = Sheets("Pivot_Table_Non_Closed_Area")
Set wsDest = Sheets("Tracking_Table_Non_Closed_Area")
With wsDest
    'C is first blank column in Row 1
    C = .Cells(1, .Columns.Count).End(xlToLeft).Column + 1
    wsTarg.Range("D12:D21").Copy .Cells(1, C) 'send to row1, first empty column
End With
 
Upvote 0
Thank you for this code, sorry for the late response. Just one thing I can not seem to get it to print the date and time at the same time the data pasted onto the new sheet, as my current code is.
 
Upvote 0

Forum statistics

Threads
1,223,234
Messages
6,170,891
Members
452,366
Latest member
TePunaBloke

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top