Change Address Text from multiple lines to a single line ?

Maverick27

Active Member
Joined
Sep 23, 2010
Messages
329
Office Version
  1. 2013
Platform
  1. Windows
Attn Excel Gurus

Anyone care to share a Macro or Excel Function to change Address text layout from multiple lines to a single line ?

1. Remove top blank space(s) shown by red box
2. Insert comma & single space after each line of text


Original format:

text-before.jpg


After Modification:

text-after.jpg


The Address is displayed on Column U of the Sheet. Row # : 194

Thanks in Advance.
 

Excel Facts

Get help while writing formula
Click the italics "fx" icon to the left of the formula bar to open the Functions Arguments dialog. Help is displayed for each argument.
Use Text to Columns in DATA tab to move to cells , use a line break (CTRL +J) as your delimiter.
315 Chinese & Thai CuisineOff the roadUpstairsDownstairsAround the BendUp in the Air


Book1
BCDEFGHIJKLMNOP
2 315 Chinese & Thai Cuisine Off the road Upstairs Downstairs Around the Bend Up in the Air315 Chinese & Thai CuisineOff the roadUpstairsDownstairsAround the BendUp in the Air315 Chinese & Thai Cuisine,Off the road,Upstairs,Downstairs,Around the Bend,Up in the Air,
Sheet1
Cell Formulas
RangeFormula
I2I2=CONCAT(C2:H2&",")

Then Concat formula to put into a single line
 
Upvote 0
Hey

Give this a go

VBA Code:
Private Sub reformat_VBA()

Dim lr As Long
With Sheet1
lr = .Cells(.Rows.Count, 21).End(3).Row
.Range("U2:U" & lr).Replace what:=Chr(10), Replacement:=", ", MatchCase:=False
.Range("U2:U" & lr).WrapText = False
For i = 2 To lr
    Debug.Print Left(.Range("U" & i), 2) = ", "
    If Left(.Range("U" & i), 2) = ", " Then .Range("U" & i).Value = Right(.Range("U" & i), Len(.Range("U" & i)) - 2)
Next i
End With
End Sub
 
Upvote 0
Hey

Give this a go

VBA Code:
Private Sub reformat_VBA()

Dim lr As Long
With Sheet1
lr = .Cells(.Rows.Count, 21).End(3).Row
.Range("U2:U" & lr).Replace what:=Chr(10), Replacement:=", ", MatchCase:=False
.Range("U2:U" & lr).WrapText = False
For i = 2 To lr
    Debug.Print Left(.Range("U" & i), 2) = ", "
    If Left(.Range("U" & i), 2) = ", " Then .Range("U" & i).Value = Right(.Range("U" & i), Len(.Range("U" & i)) - 2)
Next i
End With
End Sub
This assumes that the data you wish corrected is in column U (as per your screenshots)
 
Upvote 0
I suggest that you update your Account details (or click your user name at the top right of the forum) so helpers always know what Excel version(s) & platform(s) you are using as the best solution often varies by version. (Don’t forget to scroll down & ‘Save’)

Perhaps this?

22 09 02.xlsm
UV
1 315 Chinese & Thai Cuisine Some text Other text City etc315 Chinese & Thai Cuisine, Some text, Other text, City, etc
Reformat address
Cell Formulas
RangeFormula
V1V1=SUBSTITUTE(MID(U1,2,LEN(U1)),CHAR(10),", ")
 
Upvote 0
I suggest that you update your Account details (or click your user name at the top right of the forum) so helpers always know what Excel version(s) & platform(s) you are using as the best solution often varies by version. (Don’t forget to scroll down & ‘Save’)

Perhaps this?

22 09 02.xlsm
UV
1 315 Chinese & Thai Cuisine Some text Other text City etc315 Chinese & Thai Cuisine, Some text, Other text, City, etc
Reformat address
Cell Formulas
RangeFormula
V1V1=SUBSTITUTE(MID(U1,2,LEN(U1)),CHAR(10),", ")
Thanks everyone for your reply.

I decided to use this Function.
 
Upvote 0
You're welcome. Glad we could help. Thanks for the follow-up.

Please still update your details as requested above, as different Excel versions have different functions available to them.
 
Upvote 0
I suggest that you update your Account details (or click your user name at the top right of the forum) so helpers always know what Excel version(s) & platform(s) you are using as the best solution often varies by version. (Don’t forget to scroll down & ‘Save’)

Perhaps this?

22 09 02.xlsm
UV
1 315 Chinese & Thai Cuisine Some text Other text City etc315 Chinese & Thai Cuisine, Some text, Other text, City, etc
Reformat address
Cell Formulas
RangeFormula
V1V1=SUBSTITUTE(MID(U1,2,LEN(U1)),CHAR(10),", ")

Hello Again Peter

Can you pls fine tune the Excel Function:

=SUBSTITUTE(MID(U1,2,LEN(U1)),CHAR(10),", ")

The Data String is displayed as below in the Excel Cell:

string.jpg


When I apply the Excel Function to the cell, the result is as below:

conversion.jpg


The final output should look like:

final.jpg


Note: the semi colon which separates the Text instead of comma.

Rgds.
 
Upvote 0
I cannot access the data or expected results in a format to test and/or check the results. Can you provide it in a way that I can? (XL2BB would be best)
 
Upvote 0
MASTER.xlsx V3.xlsm
A
1Email: admin@ankole.co.ke Email: x Email: x Facebook: www.facebook.com/ankolegrill Instagram: www.instagram.com/ankolegrill Linkedin www.linkedin.com/company/ankole-grill Twitter: www.twitter.com/ankolegrill Web: www.ankole.co.ke
Sheet1
 
Upvote 0

Forum statistics

Threads
1,215,379
Messages
6,124,607
Members
449,174
Latest member
ExcelfromGermany

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