Transposing data in a specific format.

JohnBecks

New Member
Joined
Aug 9, 2021
Messages
13
Office Version
  1. 2019
Platform
  1. Windows
Hi,

I have an excel which has an unlimited number of data that needs to be transposed into a specific format. The number of columns is fixed to four but the number of rows is constantly increasing. I would appreciate the help.

Example : ( Data )

Customer Invoice Date Amount
Customer A A-1 01/08/2021 100
Customer A A-2 02/08/2021 125
Customer A A-3 03/08/2021 150
Customer A A-4 04/08/2021 175
Customer B B-1 04/08/2021 200
Customer B B-2 05/08/2021 225
Customer B B-3 06/08/2021 225
Customer B B-4 07/08/2021 250
Customer B B-5 08/08/2021 275
Customer C C-1 06/08/2021 300
Customer C C-2 07/08/2021 325
Customer C C-3 08/08/2021 350
Customer D D-1 09/08/2021 375

Into something like this - So for every

Customer AA-1A-2A-3A-4
Customer A01/08/202102/08/202103/08/202104/08/2021
Customer A100125150175
Customer BB-1B-2B-3B-4
Customer B04/08/202105/08/202106/08/202107/08/2021
Customer B200225225250
Customer BB-5---
Customer B08/08/2021---
Customer B275---
Customer CC-1C-2C-3-
Customer C06/08/202107/08/202108/08/2021-
Customer C300325350-
Customer DD-1---
Customer D09/08/2021---
Customer D375---

Appreciate all the help
 
The method I chose (because it is very fast*) transfers values only, not formatting, as you have noticed. So the target cells would be formatted as 'General' unless you had formatted them differently.

To get the formatting like the original cells, the code would need to either ..
  1. Copy and paste the original data bit-by-bit (relatively slow*), or
  2. Enter the data as values per the code above and individually format the various sections (faster but fiddly*). I mentioned fiddly since columns Q:T would not have the same formatting in every row.

* I have referenced speed of the code a number of times. This would only be relevant if your actual data might be very big, say thousands or tens of thousands of rows.

So how big is your actual data?
Do you see a reason to choose either method 1. or 2. over the other & why?
Hi Peter,


The sheet usually contains thousands of lines, and the data must be presented in a particular format - "according to company standards." So, in that case, method one should be adequate, even if slower.


However, if it is too complicated, kindly ignore it as you have significantly assisted so much already.
 
Upvote 0

Excel Facts

Can Excel fill bagel flavors?
You can teach Excel a new custom list. Type the list in cells, File, Options, Advanced, Edit Custom Lists, Import, OK
OK, see how this goes.

VBA Code:
Sub Rearrange_v5()
  Dim c As Long, r As Long, nr As Long
  
  Const MaxCols As Long = 4
  
  Application.ScreenUpdating = False
  nr = -2
  For r = 2 To Range("A" & Rows.Count).End(xlUp).Row
    If Cells(r, 1).Value = Cells(r - 1, 1).Value Then
      c = c + 1
      If c = MaxCols Then
        c = 0
        nr = nr + 3
      End If
    Else
      nr = nr + 4
      c = 0
    End If
    If c = 0 Then Cells(r, 1).Resize(, 6).Copy Destination:=Cells(nr, 11).Resize(3)
    Cells(r, 7).Resize(, 3).Copy
    Cells(nr, 17 + c).PasteSpecial Paste:=xlPasteAll, Transpose:=True
  Next r
  Application.CutCopyMode = False
  Application.ScreenUpdating = True
End Sub
 
Upvote 0

Forum statistics

Threads
1,214,984
Messages
6,122,601
Members
449,089
Latest member
Motoracer88

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