Bulk Transpose a formatted column help

Chenko0160

New Member
Joined
Nov 16, 2020
Messages
2
Office Version
  1. 365
  2. 2016
Platform
  1. Windows
Hi All,

New to the site, but you all come highly recommended by a coworker. Hoping you can steer me in the right direction on this..

We have an old PBX phone system at work, where when the data is exported it's usually in a single column text document. I'd like to be able to take the data and make a proper table out of it.

Typically the data looks like this
DN 6853
CPND
NAME Test User1
XPLN 21
DISPLAY_FMT FIRST,LAST
TYPE SL1
TN 025 0 00 12 KEY 00 H MARP DES ADMIN 20 AUG 2018
-3903​
DN 6854
CPND
NAME Test User2
XPLN 21
DISPLAY_FMT FIRST,LAST
TYPE SL1
TN 026 0 00 06 KEY 00 H MARP DES NEW 16 JAN 2015
-3904​


In the end I'm trying to take that data and make a table I can easily sort by device type, extension, name.
DN 2806CPNDNAME Test user1XPLN 21DISPLAY_FMT FIRST,LASTTYPE SL1TN 022 0 00 08 KEY 01 H MARP DES NEW 22 JUL 2013
-3904​
DN 2807CPNDNAME Test user2XPLN 21DISPLAY_FMT FIRST,LASTTYPE SL1TN 042 0 00 01 KEY 01 H MARP DES NEW 19 SEP 2014
-3903​
DN 2808CPNDNAME Test user3XPLN 21DISPLAY_FMT FIRST,LASTTYPE SL1TN 021 0 00 06 KEY 01 H MARP DES TRAIL 7 JAN 2019
-3903​
DN 2810CPNDNAME Test user4XPLN 21DISPLAY_FMT FIRST,LASTTYPE SL1TN 041 0 00 07 KEY 01 H MARP DES SUECO 17 MAY 2017
-3903​
DN 2812CPNDNAME Test user5XPLN 21DISPLAY_FMT FIRST,LASTTYPE SL1TN 042 0 00 02 KEY 01 H MARP DES SUECO 8 NOV 2017
-3903​

So far I've been manually taking each chunk of 8 lines and pasting them transposed into another tab.. and this I guess works.. but is quite manual.

Would love any suggestions you can offer, and a big thank you in advance.
-Chenko
 

Excel Facts

Who is Mr Spreadsheet?
Author John Walkenbach was Mr Spreadsheet until his retirement in June 2019.
Hi, Chenko
Welcome to the MrExcel Message Board!

Following is one of the ways to do what you need. I tried to put comments about "what's happening in this line" in the code.

Copy and paste the following VBA code in to a standard module, make sure the the active worksheet is the one you have the raw data, and execute the code.
It assumes there is a blank cell between each data set as given in your sample, and also assumes that data starts from the cell A1.

VBA Code:
Sub transposeData()
Dim sht As Worksheet
Dim rng As Range
Dim trg As Range

    ' Data is in the active sheet
    Set sht = ActiveSheet
    
    ' Need two range objects
    ' rng for the raw data
    Set rng = sht.Range("A1")
    ' trg for the new data row to keep track
    ' of the next row reference to be created
    Set trg = sht.Range("A1")
    
    ' Execute the following
    ' until there is no data left in the raw data range
    Do While Not IsEmpty(rng.Value)
        ' Set the rng until the next empty row between data sets
        Set rng = sht.Range(rng.Cells(1, 1), rng.End(xlDown))
        ' Transfer rng values to the new data row
        trg.Resize(1, rng.Rows.Count).Value = Application.WorksheetFunction.Transpose(rng)
        ' Set the next raw data row for the next iteration
        Set rng = rng.Offset(rng.Rows.Count + 1).Resize(1)
        ' Set the next new data row for the next iteration
        Set trg = trg.Offset(1)
    Loop
    ' Remove everything left after the last "new data row"
    trg.Resize(sht.UsedRange.Count).ClearContents
End Sub

So, I have this raw data (repeated first data set to make it more rows):
1151266.xlsm
A
1DN 6853
2CPND
3NAME Test User1
4XPLN 21
5DISPLAY_FMT FIRST,LAST
6TYPE SL1
7TN 025 0 00 12 KEY 00 H MARP DES ADMIN 20 AUG 2018
8-3903
9
10DN 6854
11CPND
12NAME Test User2
13XPLN 21
14DISPLAY_FMT FIRST,LAST
15TYPE SL1
16TN 026 0 00 06 KEY 00 H MARP DES NEW 16 JAN 2015
17-3904
18
19DN 6853
20CPND
21NAME Test User1
22XPLN 21
23DISPLAY_FMT FIRST,LAST
24TYPE SL1
25TN 025 0 00 12 KEY 00 H MARP DES ADMIN 20 AUG 2018
26-3903
Sheet1

And it is transformed to the following after the macro execution:
1151266.xlsm
ABCDEFGH
1DN 6853CPNDNAME Test User1XPLN 21DISPLAY_FMT FIRST,LASTTYPE SL1TN 025 0 00 12 KEY 00 H MARP DES ADMIN 20 AUG 2018-3903
2DN 6854CPNDNAME Test User2XPLN 21DISPLAY_FMT FIRST,LASTTYPE SL1TN 026 0 00 06 KEY 00 H MARP DES NEW 16 JAN 2015-3904
3DN 6853CPNDNAME Test User1XPLN 21DISPLAY_FMT FIRST,LASTTYPE SL1TN 025 0 00 12 KEY 00 H MARP DES ADMIN 20 AUG 2018-3903
Sheet1
 
Upvote 0
Solution

Forum statistics

Threads
1,224,816
Messages
6,181,139
Members
453,021
Latest member
Justyna P

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