looking for formula for converting a 2 step process

alalexbr

New Member
Joined
Oct 11, 2017
Messages
3
ok so im looking for help on create a formula on the following setup


i currently have keywords that are hypen seperated and then there is a space and then the next keyword begins -


example below and lets say i place all of these keywords on cell a2


big-car rainy-day giant-woods big-car broken-middle-finger yellow-mustard-coat furry-little-animal


what im looking to do is take cell a2 with all the keywords and have them reformated in the example below in cell a3


big car, rainy day, giant woods, big car, broken middle finger, yellow mustard coat, furry little animal




so im looking for a formula that will remove the hypen and insert a comma as shown above
any info will be greatly appreciated


thank you
 

Excel Facts

Convert text numbers to real numbers
Select a column containing text numbers. Press Alt+D E F to quickly convert text to numbers. Faster than "Convert to Number"
This custom function should do the trick.

Code:
Function Reformat(iStr As String) As StringDim SP() As String
Dim Result As String


SP = Split(iStr, " ")
Result = Replace(Join(SP, ", "), "-", " ")
Reformat = Result
End Function

Hit Alt+F11 to open the VBA editor.
Hit Alt+I+M to insert a new module.
Then paste the code above.

Then, back in your worksheeet, the formula will look like this...

Code:
=Reformat(A2)
 
Upvote 0
Or this regular formula.

Code:
=SUBSTITUTE(SUBSTITUTE(A2," ",", "),"-"," ")
 
Upvote 0
thank you . i followed your instructions and when i went to paste the formula in cell a3 and hit return visual basic window popped up and said compile error - expected: end of statement. please advise

This custom function should do the trick.

Code:
Function Reformat(iStr As String) As StringDim SP() As String
Dim Result As String


SP = Split(iStr, " ")
Result = Replace(Join(SP, ", "), "-", " ")
Reformat = Result
End Function

Hit Alt+F11 to open the VBA editor.
Hit Alt+I+M to insert a new module.
Then paste the code above.

Then, back in your worksheeet, the formula will look like this...

Code:
=Reformat(A2)
 
Upvote 0
Not sure why you were getting on error with the VBA. Oh well, glad the formula version worked for you.
 
Upvote 0
Not sure why you were getting on error with the VBA.

;) It should work fine if coded:

Code:
Function Reformat(iStr As String) As String
Dim SP() As String
...
'rather than verbatim as posted
Function Reformat(iStr As String) As StringDim SP() As String
...
 
Upvote 0

Forum statistics

Threads
1,215,007
Messages
6,122,670
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