Need Macro for transposing address in column to rows

amitks

New Member
Joined
Oct 26, 2015
Messages
8
Need Macro for transposing address in column to rows. Here is the example data:

Personal data removed per forum rules

The data is not consistent, have few or no blanks at times.
 
Last edited by a moderator:

Excel Facts

Lock one reference in a formula
Need 1 part of a formula to always point to the same range? use $ signs: $V$2:$Z$99 will always point to V2:Z99, even after copying
Welcome to the MrExcel board!

If we can assume the indication of the end of an address block is a cell ending with a space followed by 4-digits (postcode), then try this in a copy of your workbook.

Rich (BB code):
Sub TransposeAddress()
  Dim a, b
  Dim bStartNew As Boolean
  Dim i As Long, j As Long, r As Long
  
  Const MaxRowsPerAddr As Long = 8  '<- Change if you think an addr could have more rows
  
  bStartNew = True
  a = Range("A1", Range("A" & Rows.Count).End(xlUp)).Value
  ReDim b(1 To UBound(a), 1 To 8)
  For i = 1 To UBound(a)
    If a(i, 1) <> "" Then
      If bStartNew Then
        r = r + 1
        j = 1
        b(r, j) = a(i, 1)
        bStartNew = False
      Else
        j = j + 1
        b(r, j) = a(i, 1)
        If Right(a(i, 1), 5) Like " ####" Then bStartNew = True
      End If
    End If
  Next i
  With Range("B1").Resize(r, MaxRowsPerAddr)
    .Value = b
    .EntireColumn.AutoFit
  End With
End Sub
 
Last edited:
Upvote 0
Thanks a lot Peter for solving my problem.

I have another part of the problem where the end is not similar like the postcode in previous one.

Here is the data:

Personal data removed per forum rules

I used it with your macro but it returned error.

Could you please look into it?

Regards
Amit

Welcome to the MrExcel board!

If we can assume the indication of the end of an address block is a cell ending with a space followed by 4-digits (postcode), then try this in a copy of your workbook.

Rich (BB code):
Sub TransposeAddress()
  Dim a, b
  Dim bStartNew As Boolean
  Dim i As Long, j As Long, r As Long
  
  Const MaxRowsPerAddr As Long = 8  '<- Change if you think an addr could have more rows
  
  bStartNew = True
  a = Range("A1", Range("A" & Rows.Count).End(xlUp)).Value
  ReDim b(1 To UBound(a), 1 To 8)
  For i = 1 To UBound(a)
    If a(i, 1) <> "" Then
      If bStartNew Then
        r = r + 1
        j = 1
        b(r, j) = a(i, 1)
        bStartNew = False
      Else
        j = j + 1
        b(r, j) = a(i, 1)
        If Right(a(i, 1), 5) Like " ####" Then bStartNew = True
      End If
    End If
  Next i
  With Range("B1").Resize(r, MaxRowsPerAddr)
    .Value = b
    .EntireColumn.AutoFit
  End With
End Sub



Personal data removed per forum rules
 
Last edited by a moderator:
Upvote 0
Hi Peter,

I have managed to add "2345" at the end of each block. Here is the example:

Personal data removed per forum rules
Thanks a lot Peter for solving my problem.

I have another part of the problem where the end is not similar like the postcode in previous one.

Here is the data:

Personal data removed per forum rules

I used it with your macro but it returned error.

Could you please look into it?

Regards
Amit
 
Last edited by a moderator:
Upvote 0
I have managed to add "2345" at the end of each block. Here is the example:
Question... are the lines you posted that are shown in bold... are they also bold on your worksheet? If so, are they the only bold text in the column?
 
Upvote 0
Here is the link to the file

Link to personal data removed per forum rules
 
Last edited by a moderator:
Upvote 0
1. Are those real addresses, email addresses & phone numbers? If so the owners may not be too pleased at having them in a forum like this where spammers regularly hunt for email addresses especially. Refer also #13 of the Forum Rules

2. You don't really need to add anything to mark the end of these new blocks because they all have a clear marking at the beginning instead: "Practitioners:"

3. I'm not entirely clear how you want these results presented. Please give small sample of varied dummy data and the expected result.
 
Upvote 0
Here is the sample data

Personal data removed per forum rules

Thanks
Amit
 
Last edited by a moderator:
Upvote 0
1. Are those real addresses, email addresses & phone numbers? If so the owners may not be too pleased at having them in a forum like this where spammers regularly hunt for email addresses especially. Refer also #13 of the Forum Rules
You didn't answer the above question. I can remove the data from your posts if required.


Here I've disguised the data from an earlier post in case.

This should arrange your data even if not in a consistent order (apart from name being first) initially as follows
- first cell after "Practitioners:" goes to name column
- a cell only containing digits and numbers will go to mthe phone column
- a cell containing the "@" symbol to email
- a cell beginning with "www." to website.

Rich (BB code):
Sub GetIt()
  Dim a, b
  Dim i As Long, c As Long, r As Long
  Dim s As String
  
  a = Range("A1", Range("A" & Rows.Count).End(xlUp)).Value
  ReDim b(1 To UBound(a), 1 To 4)
  For i = 1 To UBound(a)
    s = a(i, 1)
    If s <> "" Then
      If LCase(s) = "practitioners:" Then
        i = i + 1
        r = r + 1
        b(r, 1) = a(i, 1)
      Else
        Select Case True
          Case IsNumeric(Replace(s, " ", "")): c = 2
          Case InStr(s, "@"): c = 3
          Case Left(LCase(s), 4) = "www.": c = 4
          Case Else: c = 5
        End Select
        If c < 5 Then b(r, c) = s
      End If
    End If
  Next i
  With Range("E2").Resize(r, 4)
    .Value = b
    .EntireColumn.AutoFit
  End With
End Sub

Excel Workbook
ABCDEFGH
1Practitioners:Practitioner NamePhoneemailwebsite
2alizabath Walkar (Mzotharajz)alizabath Walkar (Mzotharajz)03 1116 1041contact@absolutabodzhaalth.com.auwww.absolutabodzhaalth.com.au
303 1116 1041Simona Damoor (Mzotharajz)03 1314 4446
4contact@absolutabodzhaalth.com.auHazlaz Bottin (Mzotharajz)03 1764 1341mzownhaalth@hotmail.comwww.jhzsiosjot.com.au
5www.absolutabodzhaalth.com.au
6Practitioners:
7Simona Damoor (Mzotharajz)
803 1314 4446
9
10Practitioners:
11Hazlaz Bottin (Mzotharajz)
1203 1764 1341
13mzownhaalth@hotmail.com
14www.jhzsiosjot.com.au
15
Extract Data
 
Last edited:
Upvote 0

Forum statistics

Threads
1,223,236
Messages
6,170,906
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