Forum

Notifications
Clear all

Replace , by and

3 Posts
2 Users
0 Reactions
96 Views
(@bill-jone)
Posts: 28
Eminent Member
Topic starter
 

Hi,

I have a lot of sentence, Could you please help me to replace the last "," in below sentence by "and" and add "." at the end.

Input:

Aluminum Electrolytic Capacitors, Ceramic Capacitors, EMI Filters, Film Capacitors, Tantalum Capacitors, Supercapacitors, Flex Suppressor Sheets, Metal Composite Inductors, Miniature Signal Relays, EMI Cores for Cables, AC Line Filters

Output:

Aluminum Electrolytic Capacitors, Ceramic Capacitors, EMI Filters, Film Capacitors, Tantalum Capacitors, Supercapacitors, Flex Suppressor Sheets, Metal Composite Inductors, Miniature Signal Relays, EMI Cores for Cables and AC Line Filters.

 

Attached file contain the sample.

Thanks;

Bill

 

 
 
 
Posted : 17/07/2019 4:43 pm
Philip Treacy
(@philipt)
Posts: 1630
Member Admin
 

Hi Bill,

No VBA required for this, see attached workbook.

=SUBSTITUTE(A1,","," and",LEN(A1)-LEN(SUBSTITUTE(A1,",","")))

By using SUBSTITUTE to remove all commas I am shortening the length of the string by the number of commas in it.  Knowing the number of commas in the string I can then use SUBSTITUTE again to replace the last one with "and ".

You can use SUBSTITUTE to replace all occurrences of a substring, or a specific instance, and the above formula uses both approaches.

More on SUBSTITUTE

https://www.myonlinetraininghub.com/excel-substitute-formula

https://www.myonlinetraininghub.com/using-substitute-function-find-count-text

Regards

Phil

 
Posted : 17/07/2019 6:50 pm
(@bill-jone)
Posts: 28
Eminent Member
Topic starter
 

Thank you very much; your support is greatly appreciated.

Thanks;

Bill

 
Posted : 18/07/2019 5:32 pm
Share: