VBA to REMOVE MORE THAN 1 Line

TurboDieselOne

Board Regular
Joined
Oct 29, 2008
Messages
52
Hi

Sub removeFirstLine()
Application.ScreenUpdating = False
Dim selectedCell As Range
Dim arrSplit As Variant
On Error Resume Next
For Each selectedCell In Selection.Cells
arrSplit = Split(selectedCell.Value, Chr(10))
selectedCell = arrSplit(1)
Next
Application.ScreenUpdating = True
End Sub

I need to adapt this to remove more than 1 Line but not the last line.
The Lines are added using A context Menu which inserts a Name and VbCRLF char after selection a name.

Works great but I cannot seem to get it to remove more than 1 vbCrlf

The Code that adds the Line is:-

Sub OtherJointerMacro()
' This module will & Add a Gangs name to the Job
Dim MyCell As Range
On Error Resume Next
For Each MyCell In Selection.Cells
MyCell.Value = "OTHER JOINTER" & vbCrLf & MyCell.Value
Next
'With ActiveCell.Characters(Start:=1, length:=13).Font
'.Name = "Arial"
'.FontStyle = "Bold"
'End With
On Error GoTo 0
End Sub

The Bold Section was an idea that worked but when removing the line made the all the cell bold which was not good but the first line bold was good.

Any Remedies would be well appreciated

Thanks
 

Excel Facts

Control Word Wrap
Press Alt+Enter to move to a new row in a cell. Lets you control where the words wrap.
Replace: selectedCell = arrSplit(1)
with: selectedCell = arrsplit(Ubound(arrSplit))

I think that's what you're after.
 
Upvote 0
cool great any clues about the bold bit i.e if I Make the Text Bold when I add a name but can i remove the bold bit but leave the remaining unbold see the code making the Bold bit I also need to Make it so when more than more than 1 cell is selected it makes the first line bold on each of the selected cells.


Sub OtherJointerMacro()
' This module will & Add a Gangs name to the Job
Dim MyCell As Range
On Error Resume Next
For Each MyCell In Selection.Cells
MyCell.Value = "OTHER JOINTER" & vbCrLf & MyCell.Value
Next
'With ActiveCell.Characters(Start:=1, length:=13).Font
'.Name = "Arial"
'.FontStyle = "Bold"
'End With
On Error GoTo 0
End Sub


Thanks again
 
Upvote 0
Well I want to change the Macro to allow more than 1 cell Firstline BOld
Then the add the code to remove firstline to remove the bold and leave the cell unbold.

Thanks Again
 
Upvote 0
The firstline of your cell will be bold if you uncomment your code, no?

If you want to remove the bold in the delete code, add:
selectedCell.font.bold = false

after:
selectedCell = arrsplit(Ubound(arrSplit))
 
Last edited:
Upvote 0
If I Change

Sub OtherJointerMacro()
' This module will & Add a Gangs name to the Job
Dim MyCell As Range
On Error Resume Next
For Each MyCell In Selection.Cells
MyCell.Value = "OTHER JOINTER" & vbCrLf & MyCell.Value
ActiveCell.Characters(Start:=1, length:=13).Font
.Name = "Arial"
.FontStyle = "Bold"
Next
'With ActiveCell.Characters(Start:=1, length:=13).Font
'.Name = "Arial"
'.FontStyle = "Bold"
'End With
On Error GoTo 0
End Sub

So it does this Bold on Each Selected Cell is this ok? Dont seem to work.
 
Upvote 0

Forum statistics

Threads
1,224,537
Messages
6,179,405
Members
452,911
Latest member
a_barila

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