Deleting Portions of Data within a Cell

Guzzlr

Well-known Member
Joined
Apr 20, 2009
Messages
982
Office Version
  1. 2021
Platform
  1. Windows
Hello All...

I have an example, which I can't find any example of VBA to get a solution.
If I have a cell contents of: ACE-1D / F-R3. I'm trying to find code that will take away the "/F-R3" so just the "ACE-1D" remains.
This is one example, the next cell may have ACI-5 / 19...and so on.
So basically, I wish to keep everything to the left of the forward slash, and do away with everything else.
Thanks for the help
 
It needs to be like this
Code:
Dim cl As Range
For Each cl In Range("C7", Range("C" & Rows.Count).End(xlUp))
   cl.Value = Split(cl.Value, " /")(0)
Next cl
 
Upvote 0

Excel Facts

Test for Multiple Conditions in IF?
Use AND(test, test, test, test) or OR(test, test, test, ...) as the logical_test argument of IF.
It needs to be like this
Code:
Dim cl As Range
For Each cl In Range("C7", Range("C" & Rows.Count).End(xlUp))
   cl.Value = Split(cl.Value, " /")(0)
Next cl

Oh...I thought I had to define what the last row was.
 
Upvote 0
Nope, that's done here
Code:
For Each cl In Range("C7", [COLOR=#ff0000]Range("C" & Rows.Count).End(xlUp)[/COLOR])
 
Upvote 0
Nope, that's done here
Code:
For Each cl In Range("C7", [COLOR=#ff0000]Range("C" & Rows.Count).End(xlUp)[/COLOR])

Ohh yea...

So I'm trying the same type of code:
Code:
For Each cl In Range("D7", Range("D" & Rows.Count).End(xlUp))
   cl.Value = Split(cl.Value, "TCTO ")(0)
Next cl

It is finding "TCTO ". However, it's deleting the entire cell.
For example: TCTO 1695-2(G) is cleared so the cell is blank, instead of leaving 1695-2(G)?

I tried messing around with the (0) but that brought on an error. So, I'm not seeing the difference here from your previous code that found the " /"
 
Last edited:
Upvote 0
In the first request you wanted everything BEFORE the split value, now you want everything AFTER. That's why it's returning nothing.
Change the (0) to (1)
 
Upvote 0
In the first request you wanted everything BEFORE the split value, now you want everything AFTER. That's why it's returning nothing.
Change the (0) to (1)

I had tried this, and it gives me an error "Subscript out of range"
Thanks for the help
 
Last edited:
Upvote 0
Do you have any cells in the range that do not contain "TCTO "?
 
Upvote 0
Code:
For Each cl In Range("D7", Range("D" & Rows.Count).End(xlUp))
If cl.Value = "TCTO " Then
   cl.Value = Split(cl.Value, "TCTO ")(1)
   End If
Next cl

I tried putting an IF statement in, but it didn't work.
 
Upvote 0
Try
Code:
If InStr(1, Cl.Value, "TCTO ", 1) > 0 Then
 
Upvote 0

Forum statistics

Threads
1,223,911
Messages
6,175,337
Members
452,637
Latest member
Ezio2866

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