Transpose macro in excel

excel_1317

Board Regular
Joined
Jun 28, 2010
Messages
212
Full Document (2)
A
224 IP LAW GROUP FRANCE
348 rue Saint Honoré
475001 PARIS
5Tél : 33 (0) 1 44 88 98 20
6Fax : 33 (0) 1 44 88 98 46
7info@24ip.com
8www.24ip.com
9B M Robert HARRISON
10B Bénédicte REBIERE
11B M Fred SONNENBERG
12
13AB INITIO
145 rue Daunou
1575002 PARIS
16Tél : 33 (0) 1 41 40 00 73
17Fax : 33 (0) 1 42 66 02 10
18www.abinitio.eu
19M Lucie DAMBREVILLE
20M Annick PAIRAULT
21
22ADSIGNA
2323 bis rue de Turin
2475008 PARIS
25Tél : 33 (0) 1 45 00 48 48
26Fax : 33 (0) 1 40 67 95 67
27www.adsigna.com
28M Sylvie CAZAUX
29
30ARMENGAUD AINÉ
313 avenue Bugeaud
3275116 PARIS
33Tél : 33 (0) 1 45 53 05 50
34Fax : 33 (0) 1 45 53 80 21
35info@armengaud.fr
36www.armengaud.fr
37B M Bernard MICHARDIÈRE
38B Patrick MONLOUIS
39B M Chantal PEAUCELLE
40M Anne SIEFER-GAILLARDIN
41
42AUDIC
4337 rue d'Amsterdam
4475009 PARIS
45Tél : 33 (0) 1 81 29 51 60
46Fax : 33 (0) 9 50 52 86 32
47contact@cabinet-audic.fr
48www.cabinet-audic.fr
49B Hervé AUDIC
50
51B.V.
5252 rue de la Victoire
5375440 PARIS CEDEX 09
54B M Francis BEROGIN
55B M Didier BOULINGUIEZ
56B Eric BURBAUD
57B M Raphaël FLEURANCE
58B Albert HASSINE
59M Guylène KIESEL LE COSQUER
60B Cyra NARGOLWALLA
61B M Stéphane VERDURE
62
63BAROIS
6463 avenue Raymond Poincaré
6575016 PARIS
66Tél : 33 (0) 1 47 55 98 71
67Fax : 33 (0) 1 47 55 99 49
68abarois@wanadoo.fr
69M Alain BAROIS
70
71BECKER & ASSOCIÉS
7225 rue Louis le Grand
7375002 PARIS
74Tél : 33 (0) 1 53 43 85 00
75Fax : 33 (0) 1 53 43 85 05
76contact@becker.fr
77www.becker.fr
78B Philippe BECKER
79B Marion CHAJMOWICZ
80B Valérie GALLOIS
81B Camille LEBRETTE
82B M Bénédicte PIERRU
83B Redha SEKHRI
84B Anne-Caroline STARCK-LOUDES
85B Béatrice TEZIER HERMAN
86
87BERNEMAN CONSEILS
8815 rue Pelée
8975011 PARIS
90Tél : 33 (0) 6 80 10 07 17
91Fax : 33 (0) 1 43 57 01 97
92danielle.berneman@gmail.com
93B M Danielle BERNEMAN

<thead>
</thead><tbody>
</tbody>
Excel 2007





I have many data in above format. I need to put it in columns. Also there is NO uniformity in rows. The data consists of Company name, Address, Tel no. Fax no., email and contact names and in some cases website also.

So when the data is transposed into columns, due to non uniformity the data gets jumbled. PLEASE SUGGEST A WAY THROUGH WHICH THIS DATA CAN BE PUT INTO COLUMNS IN CORRECT FORMAT. Column headinngs as Company name, Address, Tel no. Fax no., email, website and contact name.
 

Excel Facts

Copy a format multiple times
Select a formatted range. Double-click the Format Painter (left side of Home tab). You can paste formatting multiple times. Esc to stop
Hi,
try using a below Code (I found it on this Forum):
Code:
Sub Transpose_Data()
Dim i&, ar As Range
    
i = 1
For Each ar In Columns("A").SpecialCells(xlConstants).Areas
    i = i + 1
    Cells(i, 2).Resize(, ar.Rows.Count).Value = Application.Transpose(ar)
Next ar
End Sub
Best regards.
 
Last edited:
Upvote 0
Hi,
try using a below Code (I found it on this Forum):
Code:
Sub Transpose_Data()
Dim i&, ar As Range
    
i = 1
For Each ar In Columns("A").SpecialCells(xlConstants).Areas
    i = i + 1
    Cells(i, 2).Resize(, ar.Rows.Count).Value = Application.Transpose(ar)
Next ar
End Sub
Best regards.


Thanks for the code. The code is not giving the desired result. As I mentioned the rows are not uniform. Please see the results that i am getting by above code.
Excel Workbook
BCDEFGHIJKLMN
1Company NameAddressPostal CodeTel No.Fax. No.EmailWebsiteContact Name
224 IP LAW GROUP FRANCE48 rue Saint Honor75001 PARISTl : 33 (0) 1 44 88 98 20Fax : 33 (0) 1 44 88 98 46info@24ip.comwww.24ip.comB M Robert HARRISONB Bndicte REBIEREB M Fred SONNENBERG
3AB INITIO5 rue Daunou75002 PARISTl : 33 (0) 1 41 40 00 73Fax : 33 (0) 1 42 66 02 10www.abinitio.euM Lucie DAMBREVILLEM Annick PAIRAULT
4ADSIGNA23 bis rue de Turin75008 PARISTl : 33 (0) 1 45 00 48 48Fax : 33 (0) 1 40 67 95 67www.adsigna.comM Sylvie CAZAUX
5ARMENGAUD AIN3 avenue Bugeaud75116 PARISTl : 33 (0) 1 45 53 05 50Fax : 33 (0) 1 45 53 80 21info@armengaud.frwww.armengaud.frB M Bernard MICHARDIREB Patrick MONLOUISB M Chantal PEAUCELLEM Anne SIEFER-GAILLARDIN
6AUDIC37 rue d'Amsterdam75009 PARISTl : 33 (0) 1 81 29 51 60Fax : 33 (0) 9 50 52 86 32contact@cabinet-audic.frwww.cabinet-audic.frB Herv AUDIC
7B.V.52 rue de la Victoire75440 PARIS CEDEX 09B M Francis BEROGINB M Didier BOULINGUIEZB Eric BURBAUDB M Raphal FLEURANCEB Albert HASSINEM Guylne KIESEL LE COSQUERB Cyra NARGOLWALLAB M Stphane VERDURE
8BAROIS63 avenue Raymond Poincar75016 PARISTl : 33 (0) 1 47 55 98 71Fax : 33 (0) 1 47 55 99 49abarois@wanadoo.frM Alain BAROISBECKER & ASSOCIS25 rue Louis le Grand75002 PARISTl : 33 (0) 1 53 43 85 00Fax : 33 (0) 1 53 43 85 05
9BERNEMAN CONSEILS15 rue Pele75011 PARISTl : 33 (0) 6 80 10 07 17Fax : 33 (0) 1 43 57 01 97danielle.berneman@gmail.comB M Danielle BERNEMAN
Full Document (2)
Excel 2007
 
Upvote 0
I think this macro (run it from your data sheet) will properly align the transposed data to the output sheet (set the OutputSheet constant... the Const statement... to the actual worksheet you want to output the data to).

Code:
Sub RedistributeData()
  Dim X As Long, Z As Long, LastRow As Long, Index As Long, Ar As Range, Data As Variant
  Const OutputSheet As String = "Sheet3"
  Const StartRow As Long = 2
  LastRow = Cells(Rows.Count, "A").End(xlUp).Row
  Set Ar = Columns("A").SpecialCells(xlConstants)
  ReDim Data(1 To Ar.Areas.Count, 1 To 8)
  Index = 1
  For X = 1 To Ar.Areas.Count
    Data(Index, 1) = Ar.Areas(X)(1)
    Data(Index, 2) = Ar.Areas(X)(2)
    Data(Index, 3) = Ar.Areas(X)(3)
    For Z = 4 To Ar.Areas(X).Rows.Count
      If Ar.Areas(X)(Z) Like "Tél : *" Then
        Data(Index, 4) = Mid(Ar.Areas(X)(Z), 7)
      ElseIf Ar.Areas(X)(Z) Like "Fax : *" Then
        Data(Index, 5) = Mid(Ar.Areas(X)(Z), 7)
      ElseIf Ar.Areas(X)(Z) Like "*@*.*" Then
        Data(Index, 6) = Ar.Areas(X)(Z)
      ElseIf Ar.Areas(X)(Z) Like "www.*.*" Then
        Data(Index, 7) = Ar.Areas(X)(Z)
      Else
        Data(Index, 8) = Data(Index, 8) & vbLf & Ar.Areas(X)(Z)
      End If
    Next
    Data(Index, 8) = Mid(Data(Index, 8), 2)
    Index = Index + 1
  Next
  With Worksheets(OutputSheet)
    .Columns("H").WrapText = True
    .Range("A1:H1").Value = Array("Company Name", "Street", "City", "Tel No.", _
                                  "Fax No.", "Email", "Website", "Contact Name")
    .Range("A2:H" & UBound(Data)) = Data
    .Rows.AutoFit
  End With
End Sub
 
Upvote 0
I think this macro (run it from your data sheet) will properly align the transposed data to the output sheet (set the OutputSheet constant... the Const statement... to the actual worksheet you want to output the data to).

Code:
Sub RedistributeData()
  Dim X As Long, Z As Long, LastRow As Long, Index As Long, Ar As Range, Data As Variant
  Const OutputSheet As String = "Sheet3"
  Const StartRow As Long = 2
  LastRow = Cells(Rows.Count, "A").End(xlUp).Row
  Set Ar = Columns("A").SpecialCells(xlConstants)
  ReDim Data(1 To Ar.Areas.Count, 1 To 8)
  Index = 1
  For X = 1 To Ar.Areas.Count
    Data(Index, 1) = Ar.Areas(X)(1)
    Data(Index, 2) = Ar.Areas(X)(2)
    Data(Index, 3) = Ar.Areas(X)(3)
    For Z = 4 To Ar.Areas(X).Rows.Count
      If Ar.Areas(X)(Z) Like "Tél : *" Then
        Data(Index, 4) = Mid(Ar.Areas(X)(Z), 7)
      ElseIf Ar.Areas(X)(Z) Like "Fax : *" Then
        Data(Index, 5) = Mid(Ar.Areas(X)(Z), 7)
      ElseIf Ar.Areas(X)(Z) Like "*@*.*" Then
        Data(Index, 6) = Ar.Areas(X)(Z)
      ElseIf Ar.Areas(X)(Z) Like "www.*.*" Then
        Data(Index, 7) = Ar.Areas(X)(Z)
      Else
        Data(Index, 8) = Data(Index, 8) & vbLf & Ar.Areas(X)(Z)
      End If
    Next
    Data(Index, 8) = Mid(Data(Index, 8), 2)
    Index = Index + 1
  Next
  With Worksheets(OutputSheet)
    .Columns("H").WrapText = True
    .Range("A1:H1").Value = Array("Company Name", "Street", "City", "Tel No.", _
                                  "Fax No.", "Email", "Website", "Contact Name")
    .Range("A2:H" & UBound(Data)) = Data
    .Rows.AutoFit
  End With
End Sub




Works Perfectly!!!! Thank You
 
Upvote 0

Forum statistics

Threads
1,216,117
Messages
6,128,935
Members
449,480
Latest member
yesitisasport

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