Find specific character at the beginning of sentence and remove

NVRensburg

Board Regular
Joined
Jul 1, 2014
Messages
113
Office Version
  1. 365
  2. 2016
Platform
  1. Windows
Please could someone help :D

I have a table with sentences in each row (see attached image). I'm importing this data into InDesign for data merge and each > stands for a return once I've imported the data, however I need to remove the > at the beginning of each sentence as I don't need a blank return at the beginning. Is there a vba that can find the > at the beginning of each sentence and remove it please?
screenshot-2024-10-15-093907-png.118083
 

Attachments

  • Screenshot 2024-10-15 093907.png
    Screenshot 2024-10-15 093907.png
    18.9 KB · Views: 33

Excel Facts

Formula for Yesterday
Name Manager, New Name. Yesterday =TODAY()-1. OK. Then, use =YESTERDAY in any cell. Tomorrow could be =TODAY()+1.
will this work
VBA Code:
Sub RemoveFirstCharacterInEachCell()
For Each cell In Range("A1", Range("A65536").End(xlUp))
If Not IsEmpty(cell) Then
cell.value = Right(cell, Len(cell) - 1)
End If
Next cell
End Sub
 
Upvote 0
will this work
VBA Code:
Sub RemoveFirstCharacterInEachCell()
For Each cell In Range("A1", Range("A65536").End(xlUp))
If Not IsEmpty(cell) Then
cell.value = Right(cell, Len(cell) - 1)
End If
Next cell
End Sub
Yes thank you!
 
Upvote 0
Yes thank you!
If that code works for you then rather than processing the data one line at a time, you could do the lot at once with this one-liner.
I have assumed a heading with data starting at row 2 but if that is not the case just edit that A2 in the code.

Excel Formula:
Sub RemoveFirst()
  Range("A2", Range("A" & Rows.Count).End(xlUp)).TextToColumns DataType:=xlFixedWidth, FieldInfo:=Array(Array(0, 9), Array(1, 1))
End Sub

@AC PORTA VIA
A couple of code comments
  • For many years now worksheets have had more than the old 65,536 rows so using that number as you have could miss data in some worksheets. I suggest changing to use the generic Rows.Count as I have done above and that will work in both new and old worksheet sizes.

  • In vba the Mid function's 3rd argument is optional and omitting it gives a good way to return a string starting at any position. So instead of using Right and Len as you have done, the code below would do the same job.
    An added advantage of using this Mid structure is that it does not matter if the cell is empty so there would be no need for the Not IsEmpty() check
Rich (BB code):
cell.Value = Right(cell, Len(cell) - 1)
cell.Value = Mid(cell, 2)
 
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,181
Members
453,022
Latest member
Mohamed Magdi Tawfiq Emam

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