To delete comma when split the text by using VBA code

Kenor

Board Regular
Joined
Dec 8, 2020
Messages
116
Office Version
  1. 2016
Platform
  1. Windows
Hi,

I use below code to split the text without any comma,

Sub RSplit()
For I = 2 To Cells(Rows.Count, 3).End(xlUp).Row
mysplit = Split(Cells(I, 3).Value & " #", " ", , vbTextCompare)
Cells(I, 3).Resize(1, UBound(mysplit)).Value = mysplit
Next I
End Sub

But if text have comma, how to edit the code ?
By manual, only need to choose Delimeted (for character such as comma ).

Can help me?

Thanks
 

Attachments

  • To delete comma after split the text.PNG
    To delete comma after split the text.PNG
    65.5 KB · Views: 17

Excel Facts

How to create a cell-sized chart?
Tiny charts, called Sparklines, were added to Excel 2010. Look for Sparklines on the Insert tab.
Try updating this instruction:
VBA Code:
mySplit = Split(Replace(Cells(I, 3).Value, ", ", " ", , , vbTextCompare) & " #", " ", , vbTextCompare)
Bye
 
Upvote 0
new one:
VBA Code:
mysplit = Split(Cells(I, 3).Value & ", #", ", ", , vbTextCompare)
 
Upvote 0
Try updating this instruction:
VBA Code:
mySplit = Split(Replace(Cells(I, 3).Value, ", ", " ", , , vbTextCompare) & " #", " ", , vbTextCompare)
Bye
I already try, comma has disappeared after split.
But the column header also change after split.
 

Attachments

  • Before.PNG
    Before.PNG
    32.6 KB · Views: 7
  • After.PNG
    After.PNG
    32.9 KB · Views: 7
Upvote 0
Maybe the solution proposed by @mart37, see message #4, is more appropriate (if your text always contains both comma + space)...

Or start splitting from row 3 rather then 2:

VBA Code:
For I = 3 To Cells(Rows.Count, 3).End(xlUp).Row

Bye
 
Upvote 0

Forum statistics

Threads
1,215,006
Messages
6,122,665
Members
449,091
Latest member
peppernaut

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