Excel Data Manipulation - Transpose

ls010s

New Member
Joined
May 8, 2013
Messages
16
HiI need to transpose some data as follows, for which a normal transpose doesn't seem to work.I have cost centre in column A, Account Code in column B, Description in column C, and then column D to O has values phased by month (Jan-Dec) with headings in row 1.What I want is to transpose this so that column D becomes a list of the month and column e becomes the value for that specific month and dimension. So say if I have 10 rows of data every month, then cell d2:d12 would say Jan and e2:e12 will have the value, then d13:d23 would say Feb and e13:e23 will have feb values and so on.At the moment I am using copy and paste to obtain the data from colum a to c and copy it down 12 times, and then copy all values to column e by means of copy and paste and manually input the dates in column d, again by means of copying and pasting.Much appreciated.
 

Excel Facts

How to show all formulas in Excel?
Press Ctrl+` to show all formulas. Press it again to toggle back to numbers. The grave accent is often under the tilde on US keyboards.
ls010s,

Welcome to the MrExcel forum.

What version of Excel are you using?

Can you post a screenshot of the raw data worksheet, and, post a screenshot of the worksheet results (manually formatted by you) that you are looking for?

To post your data, you can download and install one of the following two programs:
Excel Jeanie
MrExcel HTML Maker


If you are not able to give us screenshots:
You can upload your workbook to Box Net,
sensitive data scrubbed/removed/changed
mark the workbook for sharing
and provide us with a link to your workbook.
 
Upvote 0
Hihiker95

I am using Excel 2007.


ls010s,

Welcome to the MrExcel forum.

What version of Excel are you using?

Can you post a screenshot of the raw data worksheet, and, post a screenshot of the worksheet results (manually formatted by you) that you are looking for?

To post your data, you can download and install one of the following two programs:
Excel Jeanie
MrExcel HTML Maker


If you are not able to give us screenshots:
You can upload your workbook to Box Net,
sensitive data scrubbed/removed/changed
mark the workbook for sharing
and provide us with a link to your workbook.
 
Upvote 0
Hi Hiker 95

I have uploaded the file and below is the link to access it. This shows where I am and where I would like to get.

https://drive.google.com/folderview?id=0BzsDpPI91t9FVkl4UDQwZjBNa0E&usp=sharing

Thanks in advance




ls010s,

Welcome to the MrExcel forum.

What version of Excel are you using?

Can you post a screenshot of the raw data worksheet, and, post a screenshot of the worksheet results (manually formatted by you) that you are looking for?

To post your data, you can download and install one of the following two programs:
Excel Jeanie
MrExcel HTML Maker


If you are not able to give us screenshots:
You can upload your workbook to Box Net,
sensitive data scrubbed/removed/changed
mark the workbook for sharing
and provide us with a link to your workbook.
 
Upvote 0
ls010s,

Please do not quote entire replies from your helper. When quoting follow these guidelines:
1. Quote ONLY if it is needed to add clarity or context for your reply. If so, then
2. Quote ONLY the specific part of the post that is relevant - - not the entire post.

This will keep thread clutter to a minimum and make the discussion easier to follow.


Thanks for the workbook.

Would you like results to be in a new worksheet Results?
 
Upvote 0
Hi hiker95

I would prefer if it was in a new worksheet however I am happy if it remains in the same worksheet.

Thanks
 
Upvote 0
ls010s,

Sample raw data in worksheet Sheet1:


Excel 2007
ABCDEFGHIJKLMNO
1CCNominalDescriptionJan-13Feb-13Mar-13Apr-13May-13Jun-13Jul-13Aug-13Sep-13Oct-13Nov-13Dec-13
2101A1256Drinks100100100150150150100100100100100150
3101A1033Salary150016001700180019002000210022002300240025002600
4101A1095Tax125125125125125125125125125125125125
5101A2350Telecom555555555555555555555555
6101A2005IT656565656565656565656565
7101A2004Internet353535353535353535353535
8101A3050Equipment959595959595959595959595
9101A3215Facilities105105105105105105105105105105105105
10101A4010Motor Runnings303030303030303030303030
11101A1560Bank Charges171717171717171717171717
12
Sheet1


After the macro in a new worksheet Results (not all rows are shown for brevity):


Excel 2007
ABCDE
1CCNominalDescriptionPeriodAmount
2101A1256DrinksJan-13100
3101A1033SalaryJan-131500
4101A1095TaxJan-13125
5101A2350TelecomJan-1355
6101A2005ITJan-1365
7101A2004InternetJan-1335
8101A3050EquipmentJan-1395
9101A3215FacilitiesJan-13105
10101A4010Motor RunningsJan-1330
11101A1560Bank ChargesJan-1317
12101A1256DrinksFeb-13100
13101A1033SalaryFeb-131600
14101A1095TaxFeb-13125
15101A2350TelecomFeb-1355
16101A2005ITFeb-1365
17101A2004InternetFeb-1335
18101A3050EquipmentFeb-1395
19101A3215FacilitiesFeb-13105
20101A4010Motor RunningsFeb-1330
21101A1560Bank ChargesFeb-1317
Results


Please TEST this FIRST in a COPY of your workbook (always make a backup copy before trying new code, you never know what you might lose).

1. Copy the below code, by highlighting the code and pressing the keys CTRL + C
2. Open your workbook
3. Press the keys ALT + F11 to open the Visual Basic Editor
4. Press the keys ALT + I to activate the Insert menu
5. Press M to insert a Standard Module
6. Where the cursor is flashing, paste the code by pressing the keys CTRL + V
7. Press the keys ALT + Q to exit the Editor, and return to Excel
8. To run the macro from Excel, open the workbook, and press ALT + F8 to display the Run Macro Dialog. Double Click the macro's name to Run it.

Code:
Option Explicit
Sub ReorgData()
' hiker95, 05/08/2013
' http://www.mrexcel.com/forum/excel-questions/701493-excel-data-manipulation-transpose.html
Dim a As Variant, b As Variant
Dim lr As Long, lc As Long, i As Long, ii As Long, c As Long
Application.ScreenUpdating = False
With Sheets("Sheet1")
  lr = .Cells(Rows.Count, 1).End(xlUp).Row
  lc = .Cells(1, Columns.Count).End(xlToLeft).Column
  a = .Range(.Cells(1, 1), .Cells(lr, lc))
  ReDim b(1 To (UBound(a, 1) + 1) * (UBound(a, 2) - 3), 1 To 5)
End With
ii = ii + 1
b(ii, 1) = "CC": b(ii, 2) = "Nominal": b(ii, 3) = "Description"
b(ii, 4) = "Period": b(ii, 5) = "Amount"
For c = 4 To lc Step 1
  For i = 2 To UBound(a, 1)
    ii = ii + 1
    b(ii, 1) = a(i, 1)
    b(ii, 2) = a(i, 2)
    b(ii, 3) = a(i, 3)
    b(ii, 4) = a(1, c)
    b(ii, 5) = a(i, c)
  Next i
Next c
If Not Evaluate("ISREF(Results!A1)") Then Worksheets.Add().Name = "Results"
With Sheets("Results")
  .UsedRange.ClearContents
  .Cells(1, 1).Resize(UBound(b, 1), UBound(b, 2)) = b
  .Cells(1, 1).Resize(, 5).Font.Bold = True
  .Range("D2:D" & UBound(b, 1)).NumberFormat = "mmm-yy"
  .Columns.AutoFit
  .Activate
End With
Application.ScreenUpdating = True
End Sub

Before you use the macro with Excel 2007 or newer, save your workbook, Save As, a macro enabled workbook with the file extension .xlsm

Then run the ReorgData macro.
 
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