Remove part of a sting in a cell

jo_jan

New Member
Joined
Feb 12, 2019
Messages
5
I would like to split the date next to my text in the cell below using a vba code, but the text will sometimes change and i only want the text in the first cell, not the date.
The first column of my table is what I have and the right column is what I want.


[TABLE="width: 500"]
<tbody>[TR]
[TD]JOHN (02/02/19)[/TD]
[TD]JOHN[/TD]
[/TR]
[TR]
[TD][/TD]
[TD]02/02/19[/TD]
[/TR]
</tbody>[/TABLE]
 

Excel Facts

Move date out one month or year
Use =EDATE(A2,1) for one month later. Use EDATE(A2,12) for one year later.
Will the date always be at the end? Do you want the end result in the first column or copied somewhere else?
 
Upvote 0
The date I want is the one written next to JOHN. Thew result I want is only 2 columns with the text and the date under. I don't want to keep the first column.
 
Upvote 0
Can you give us a few more examples of what you data looks like? For example, can there be more than 2 or 3 words in the cells? Is the date always at the end of the cell?
 
Upvote 0
Can you give us a few more examples of what you data looks like? For example, can there be more than 2 or 3 words in the cells? Is the date always at the end of the cell?

No there is only one word before the date and there is always a space between them. And yes the date is always at the end of the cell! Thanks!
 
Upvote 0
Try this macro. It assumes your data starts in row 2. If it starts in row 1, change the 2 (in red) to a 1.
Code:
Sub RemoveSubstring()
    Application.ScreenUpdating = False
    Dim LastRow As Long, x As Long, splitRng As Variant
    LastRow = Cells.Find("*", SearchOrder:=xlByRows, SearchDirection:=xlPrevious).Row
    For x = LastRow To [COLOR="#FF0000"]2 [/COLOR]Step -1
        splitRng = Split(Cells(x, 1), " ")
        Rows(x + 1).Insert
        Cells(x + 1, 1) = splitRng(1)
        Cells(x, 1) = splitRng(0)
    Next x
    Application.ScreenUpdating = True
End Sub
 
Upvote 0

Forum statistics

Threads
1,224,820
Messages
6,181,160
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