Archiving data horizontally

sobrien

Board Regular
Joined
Feb 28, 2006
Messages
179
I want to create a macro to archive data from a sheet into another sheet and create a continuous horizontal list. As follows:
I want to copy columns C:I in sheet "Accounts" and then paste into sheet "Account history" but so it pastes onto the next column at the end of the existing data.


Thanks
 

Excel Facts

Lock one reference in a formula
Need 1 part of a formula to always point to the same range? use $ signs: $V$2:$Z$99 will always point to V2:Z99, even after copying

al_b_cnu

Well-known Member
Joined
Jul 18, 2003
Messages
4,526
Hi,

do you want the entire contents of C:Icopying, or just he last row?
 

al_b_cnu

Well-known Member
Joined
Jul 18, 2003
Messages
4,526
Try this:
Code:
Option Explicit

Sub TransposeData()
Dim iToCol As Integer
Dim rFrom As Range
Dim wsFr As Worksheet, wsTo As Worksheet

Set wsFr = Sheets("Accounts")
Set wsTo = Sheets("Accounts History")
iToCol = wsTo.Cells(1, Columns.Count).End(xlToLeft).Column + 1

Set rFrom = Intersect(wsFr.Columns("C:I"), wsFr.UsedRange)

rFrom.Copy
wsTo.Range(Cells(1, iToCol).Address).PasteSpecial Paste:=xlPasteValues, Transpose:=True
Application.CutCopyMode = False

End Sub
 

Forum statistics

Threads
1,176,348
Messages
5,902,635
Members
434,983
Latest member
JenniferNash

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
Top