Move data from blocks to vertical rows

Hagbo

New Member
Joined
May 29, 2016
Messages
3
Hi all,

I am looking to move data from this format:
<!--[if !mso]><style>v\:* {behavior:url(#default#VML);}o\:* {behavior:url(#default#VML);}x\:* {behavior:url(#default#VML);}.shape {behavior:url(#default#VML);}</style><![endif]-->
Trading Name:BRAD GARLICK FORD
Division:[ Automobile Dealers Metro ]
Address:2-16 BLAXLAND ROAD
RYDE
NSW, 2112
Phone:02 9807-2933
Fax:02 9808-2501

<tbody>
</tbody>

Trading Name:BROOKVALE MAZDA
Division:[ Automobile Dealers Metro ]
Address:786 PITTWATER RD
BROOKVALE
NSW, 2100
Phone:029939-7677
Fax:029939-7944

<tbody>
</tbody>

To this format:
Trading NameDivisionAddressAddress 1StatePostcodePhoneFax
BRAD GARLICK FORDAutomobile Dealers Metro2-16 BLAXLAND ROADRYDENSW211202 9807-2933029939-7944
BROOKVALE MAZDAAutomobile Dealers Metroblahblahblahblahblahblah

<tbody>
</tbody>

I'm basically wanting to convert blocks of data to logical rows and columns as well as split out the postcode and state from the same cell into another column.

Any help would be appreciated!

Regards,

Paul
 

Excel Facts

Square and cube roots
The =SQRT(25) is a square root. For a cube root, use =125^(1/3). For a fourth root, use =625^(1/4).
Each entry should only be one row, not the 2 showing above E.g. "Brad Garlick Ford" should be one row, not have "Ford" on a separate row.
 
Upvote 0
Welcome to the MrExcel board!

Try this in a copy of your workbook.

Rich (BB code):
Sub RearrangeDetails()
   Dim a As Variant, b As Variant, adrbits As Variant
   Dim i As Long, j As Long, k As Long, UB As Long
   Dim adr As String
   
   a = Range("A1", Range("B" & Rows.Count).End(xlUp)).Value
   ReDim b(1 To UBound(a), 1 To 8)
   For i = 1 To UBound(a)
    If Not IsEmpty(a(i, 2)) Then
      Select Case LCase(a(i, 1))
        Case "trading name:"
          k = k + 1
          b(k, 1) = a(i, 2)
        Case "division:"
          b(k, 2) = Trim(Replace(Replace(a(i, 2), "[", ""), "]", ""))
        Case "address:"
          adr = a(i, 2)
        Case ""
          adr = adr & ":" & a(i, 2)
        Case "phone:"
          adrbits = Split(adr, ":")
          UB = UBound(adrbits)
          adr = adrbits(0)
          For j = 1 To UB - 2
            adr = adr & vbLf & adrbits(j)
          Next j
          b(k, 3) = adr
          b(k, 4) = adrbits(UB - 1)
          b(k, 5) = Split(adrbits(UB), ",")(0)
          b(k, 6) = Trim(Split(adrbits(UB), ",")(1))
          b(k, 7) = a(i, 2)
        Case "fax:"
          b(k, 8) = a(i, 2)
      End Select
    End If
   Next i
   With Range("F1:M1")
    .Value = Array("Trading Name", " Division", "Address", "Address 1", "State", "Postcode", "Phone", "Fax")
    .Offset(1).Resize(k).Value = b
    .EntireColumn.AutoFit
   End With
End Sub



Sample data & results. I've assumed some address blocks contain more than 3 rows - see rows 22-25.

Excel Workbook
ABCDEFGHIJKLM
1Trading NameDivisionAddressAddress 1StatePostcodePhoneFax
2Trading Name:BRAD GARLICK FORDBRAD GARLICK FORDAutomobile Dealers Metro2-16 BLAXLAND ROADRYDENSW211202 9807-293302 9808-2501
3Division:[ Automobile Dealers Metro ]BROOKVALE MAZDAAutomobile Dealers Metro786 PITTWATER RDBROOKVALENSW2100029939-7677029939-7944
4Address:2-16 BLAXLAND ROADSOMEBODYAutomobile Dealers MetroShop 23Big Industrial EstateSOME TOWNNSW222202 123-456026639-7944
5RYDE
6NSW, 2112
7Phone:02 9807-2933
8Fax:02 9808-2501
9
10
11Trading Name:BROOKVALE MAZDA
12Division:[ Automobile Dealers Metro ]
13Address:786 PITTWATER RD
14BROOKVALE
15NSW, 2100
16Phone:029939-7677
17Fax:029939-7944
18
19
20Trading Name:SOMEBODY
21Division:[ Automobile Dealers Metro ]
22Address:Shop 23
23Big Industrial Estate
24SOME TOWN
25NSW, 2222
26Phone:02 123-456
27Fax:026639-7944
Rearrange Data
 
Last edited:
Upvote 0

Forum statistics

Threads
1,215,471
Messages
6,125,000
Members
449,202
Latest member
Pertotal

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