Aligment of specific text. text

Panoos64

Well-known Member
Joined
Mar 1, 2014
Messages
890
All hi, i would like to create a VBA code so that to run through col. "H" and where find a cell which contains the below break text, should make it to one line. Therefore that the break text is in same cell. In my below extract the "H" is the col. and "12" is the row. I present below the original data and expected result.

Thank you all in advance


Original data

H
12 Welfare Fund Summary Totals
Employer 1


Expected result

H
12 Welfare Fund Summary Totals Employer 1
 
Last edited:

Excel Facts

Repeat Last Command
Pressing F4 adds dollar signs when editing a formula. When not editing, F4 repeats last command.
If those cells contain a standard line break, then simply select the column
Ctrl H in the find what box enter Ctrl J
Leave the replace box empty & click ok
 
Upvote 0
All hi, i would like to create a VBA code so that to run through col. "H" and where find a cell which contains the below break text, should make it to one line. Therefore that the break text is in same cell. In my below extract the "H" is the col. and "12" is the row. I present below the original data and expected result.

Thank you all in advance


Original data

H
12 Welfare Fund Summary Totals
Employer 1


Expected result

H
12 Welfare Fund Summary Totals Employer 1

Here is code to check each cell in the range and remove the line break.

Code:
Sub Panoos64()

Dim wb As Workbook
Dim ws As Worksheet
Dim str As String
Dim lngROW As Long, lngCOL As Long
Dim rng As Range, cell As Range
Dim intCOL As Integer


Set wb = ThisWorkbook
Set ws = wb.Sheets("Panoos64")  'change sheet name to your sheet name
Set cell = Application.InputBox("Select the range to process", Type:=8)
intCOL = cell.Column

With ws
lngROW = ws.Cells.Find(What:="*", _
        after:=ws.Cells(1), _
        LookAt:=xlPart, _
        LookIn:=xlFormulas, _
        SearchOrder:=xlByRows, _
        SearchDirection:=xlPrevious, _
        MatchCase:=False).Row
lngCOL = ws.Cells.Find(What:="*", _
        after:=ws.Cells(1), _
        LookAt:=xlPart, _
        LookIn:=xlFormulas, _
        SearchOrder:=xlByColumns, _
        SearchDirection:=xlPrevious, _
        MatchCase:=False).Column
Set rng = ws.Range(ws.Cells(1, intCOL), ws.Cells(lngROW, intCOL))
For Each cell In rng
On Error Resume Next
    cell.Value = Replace(cell.Value, vbLf, " ")
On Error GoTo 0
Next cell
        
End With


End Sub
 
Upvote 0
RCBric, i would like to thank you. your code works but with it appears "Input Box" in order to choose the column. However the column is the "H" and so is it possible to modify it so that to get it by default without use the "Input Box"? Thank you for your support . Hv a nice day
 
Upvote 0
Try
Code:
Sub MM1()
Dim lr As Long
lr = Cells(Rows.Count, "H").End(xlUp).Row
For Each cell In Range("H1:H" & lr)
On Error Resume Next
    cell.Value = Replace(cell.Value, vbLf, " ")
On Error GoTo 0
Next cell
End Sub
 
Upvote 0
Hi Fluf, i followed your above instructions but it doesn't work. Is it possible by VBA code? Thank you once again for your support
 
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,178
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