Jyggalag

Active Member
Joined
Mar 8, 2021
Messages
422
Office Version
  1. 365
  2. 2019
Platform
  1. Windows
Hi all,

I currently have a very large data sheet that looks like this:

1660291617565.png


In this example, I've just put in a format of: Date,Name,Gender

Please note that some of the cells however might only have Date,Gender or Name,Gender or Date,Gender etc.

My ideal format would be: Date,Name,Gender

However, as you can see, many of them have it pasted as "Date,,,, Name ,,,Gender" with a lot of unnecessary commas and spaces

Does anybody know how to remove these duplicate values? Essentially I want all cells to have zero spaces and just one comma inbetween the values (so Date,Name,Gender as the format)

I would truly appreciate some assistance here! :)

Thank you all!

Kind regards,
Jyggalag
 

Excel Facts

Back into an answer in Excel
Use Data, What-If Analysis, Goal Seek to find the correct input cell value to reach a desired result
Perhaps:

=TEXTJOIN(",",TRUE,IFERROR(SUBSTITUTE(FILTERXML("<t><s>"&SUBSTITUTE(SUBSTITUTE(A1,"/","."),",","</s><s>")&"</s></t>","//s"),".","/"),""))

* I think there is a TEXTSPLIT function now, but it hasn't been released on my 365 yet.
 
Upvote 0
Upvote 0
Solution
You could copy your data to a Text Editor that supports Regular Expressions, then do the Replace Job and copy your data back to Excel.

Here is an example how to replace your data to match your requirements with the Notepad++ Text Editor:

npp_sr_1.jpg


npp_sr_2.jpg


Here is the Regular Expression that will find one single row of data:
^(\d\d/\d\d/\d\d\d\d)?[, ]*([a-zA-Z]+)?[, ]*(Male|Female)?.*

And this expression (Notepad++ Syntax) would replace the data to match the requirements:
\1,\2,\3
 
Upvote 0
You could copy your data to a Text Editor that supports Regular Expressions, then do the Replace Job and copy your data back to Excel.
If using Regular Expressions then you could keep it in Excel and do the Regular Expression manipulation there since Excel already supports Regular Expressions via vba.
 
Upvote 0
If you don't have those latest TEXT functions yet, try

22 08 12.xlsm
AB
112/08/2022,George,,,Male12/08/2022,George,Male
211/08/2022,,,Elizabeth,,,Female11/08/2022,Elizabeth,Female
310/08/2022 ,,Thomas ,,Male10/08/2022,Thomas,Male
409/08/2022,,,,,Female09/08/2022,Female
5John ,,,,MaleJohn,Male
Commas
Cell Formulas
RangeFormula
B1:B5B1=SUBSTITUTE(TRIM(SUBSTITUTE(SUBSTITUTE(A1," ",""),","," "))," ",",")
I was a bit worried that the name may actually contain first name and last names with legitimate spaces. Course I'm just speculating :)
 
Upvote 0

Forum statistics

Threads
1,215,063
Messages
6,122,935
Members
449,094
Latest member
teemeren

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