Char(10)

Obied70

Board Regular
Joined
Nov 4, 2015
Messages
177
Office Version
  1. 365
Platform
  1. Windows
Hi Geniuses,
I need some help inserting line breaks where a cell contains a certain word. For example the address line "100 East King Way Suite 100" needs to have a line break so that "Suite 100" is on another line in the same cell. I would do it manually but I have ~40,000 rows to go through so using a formula/vba is a much better option. Thanks for your help!
 

Excel Facts

Bring active cell back into view
Start at A1 and select to A9999 while writing a formula, you can't see A1 anymore. Press Ctrl+Backspace to bring active cell into view.
Re: Char(10) Help

VBA is fine here too if theres no simple cell formula to use
 
Upvote 0
Re: Char(10) Help

Hi, what is the rule for where CRLF needs inserting? Is it always the second to last space?
 
Last edited:
Upvote 0
Re: Char(10) Help

If it's always "Suite", you can just use Find/Replace:
-Select the data
-Ctrl+H
-Enter Suite in the Find box
-Click in the replace box, press Ctrl+J and then type Suite
-Press Replace all
 
Upvote 0
Re: Char(10) Help

It's going to be a variation of "suite" with varying number of characters after. So I need, every time the word "suite", "ste", etc is found, to place "suite" and everything after that on the next line in the same cell
 
Upvote 0
Re: Char(10) Help

I found VBA code here that removes those soft carriage returns: https://www.ablebits.com/office-addins-blog/2013/12/03/remove-carriage-returns-excel/
We can reverse it to add them in before every incidence of the word "Suite", like this:
Code:
Sub AddCarriageReturns()
    Dim MyRange As Range
    Application.ScreenUpdating = False
    Application.Calculation = xlCalculationManual
 
    For Each MyRange In ActiveSheet.UsedRange
        If InStr(MyRange, "Suite") > 0 Then
            MyRange = Replace(MyRange, "Suite", Chr(10) & "Suite")
        End If
    Next
 
    Application.ScreenUpdating = True
    Application.Calculation = xlCalculationAutomatic
End Sub
 
Upvote 0
Re: Char(10) Help

Maybe, where the address is in A1
Code:
=TRIM(IF(ISNUMBER(SEARCH("suite",A1)),LEFT(A1,SEARCH(" Suite",A1)-1)&CHAR(10)&MID(A1,SEARCH("suite",A1),999),A1))
 
Upvote 0
Re: Char(10) Help

If different cases is an issue (i.e. Suite, suite, SUITE), then you can use this version of VBA code.
Code:
Sub AddCarriageReturns()
    Dim MyRange As Range
    Application.ScreenUpdating = False
    Application.Calculation = xlCalculationManual
 
    For Each MyRange In ActiveSheet.UsedRange
        If InStr(UCase(MyRange), "SUITE") > 0 Then
            MyRange = Replace(UCase(MyRange), "SUITE", Chr(10) & "Suite")
        End If
    Next
 
    Application.ScreenUpdating = True
    Application.Calculation = xlCalculationAutomatic
End Sub
 
Upvote 0
Re: Char(10) Help

You guys never fail to blow my tiny little brain to bits. I'll give this a whirl and report back
 
Upvote 0
Re: Char(10) Help

I'm getting a type mismatch and so the macro is not running through the entirety of the sheet.
 
Upvote 0

Forum statistics

Threads
1,223,911
Messages
6,175,329
Members
452,635
Latest member
laura12345

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