How can I replace commas with a line feed in a single cell?

I am building an import spreadsheet to go into a particular database.  The database vendor has a very specific format that the table must be in to work.  Here's where I'm having trouble

On a given row, some of the fields contain multiple items, separated by commas.  In order for the import to work, these items need to be separated by a line-feed within the cell, instead of a comma.  I've tried to illustrate this below....   Any ideas on how to do some kind of find-and-replace that would change the commas to line feeds?

What the table looks like now:

ID Name Age Keyword
1 Apple Pediatric Red,White,Blue
2 Banana Adult,Teen Blue,Green,Purple,Brown
3 Grape Pediatric,Teen Black,White

What it needs to look like:

ID Name Age Keyword
1 Apple Pediatric Red
White
Blue
2 Banana Adult
Teen
Blue
Green
Purple
Brown
3 Grape Pediatric
Teen
Black
White

Answer
Answer

Try this...

• Select the Keyword range of cells
• Home.Find&Select.Replace
...Find what: ,
...Replace with: CTRL+SHIFT+J  (for some reason Excel converts that to a carriage return)
...Click: Replace All

Does that help?


Ron Coderre
Microsoft MVP (2006 - 2010) - Excel

P.S. If any post answers your question, please mark it as the Answer (so it won't keep showing as an open item.)
Regards,

Ron Coderre
Former Microsoft MVP - Excel

16 people found this reply helpful

·

Was this reply helpful?

Sorry this didn't help.

Great! Thanks for your feedback.

How satisfied are you with this reply?

Thanks for your feedback, it helps us improve the site.

How satisfied are you with this reply?

Thanks for your feedback.

Answer
Answer

Hi,

use the following macro:

  • Alt+F11 to open the VBA editor
  • Insert > Module
  • Copy the code in the module
  • Alt+F11 back to Excel view
  • Select the appropriate cells
  • Alt+F8, select macro name > Run.

Sub ReplaceComma()
Dim rngCell As Range
  For Each rngCell In Selection
    rngCell.Value = Replace(rngCell, ",", vbLf)
  Next
End Sub

 

Regards,

Frank


If this post answers your question, please mark it for all readers as the Answer or vote if the reply has been helpful.

If this post answers your question, please mark it as the answer or vote it as helpfull.

12 people found this reply helpful

·

Was this reply helpful?

Sorry this didn't help.

Great! Thanks for your feedback.

How satisfied are you with this reply?

Thanks for your feedback, it helps us improve the site.

How satisfied are you with this reply?

Thanks for your feedback.

 
 

Question Info


Last updated February 16, 2023 Views 31,687 Applies to: