kelly mort
Well-known Member
- Joined
- Apr 10, 2017
- Messages
- 2,169
- Office Version
- 2016
- Platform
- Windows
<code style="box-sizing: inherit; margin: 0px; padding: 0px; border: 0px; font-style: inherit; font-variant: inherit; font-weight: inherit; font-stretch: inherit; line-height: inherit; font-family: Consolas, Menlo, Monaco, "Lucida Console", "Liberation Mono", "DejaVu Sans Mono", "Bitstream Vera Sans Mono", "Courier New", monospace; vertical-align: baseline; max-height: 300px; overflow: auto;">
Found this code online and need help make it do what I want.
I want replace the last comma with "and" instead of this replacing all spaces with comma .
There may be :
1. No word
2. Only one word
3. Only two words
4. More than two words.
So I want all those factors considered.
Thanks </code>
Code:
Sub [COLOR=#303336]example[/COLOR][COLOR=#303336]()[/COLOR][COLOR=#303336]
[/COLOR][COLOR=#101094]Dim[/COLOR][COLOR=#303336] s1 [/COLOR][COLOR=#101094]As[/COLOR][COLOR=#101094]String[/COLOR][COLOR=#303336],[/COLOR][COLOR=#303336] s2 [/COLOR][COLOR=#101094]As[/COLOR][COLOR=#101094]String[/COLOR][COLOR=#303336]
[/COLOR][COLOR=#101094]Dim[/COLOR][COLOR=#303336] pos [/COLOR][COLOR=#101094]As[/COLOR][COLOR=#101094]Integer[/COLOR][COLOR=#303336]
s1 [/COLOR][COLOR=#303336]=[/COLOR][COLOR=#303336] ActiveSheet[/COLOR][COLOR=#303336].[/COLOR][COLOR=#303336]ActiveCell[/COLOR][COLOR=#303336].[/COLOR][COLOR=#303336]Value
s2 [/COLOR][COLOR=#303336]=[/COLOR][COLOR=#7D2727]""[/COLOR][COLOR=#303336]
pos [/COLOR][COLOR=#303336]=[/COLOR][COLOR=#303336] InStr[/COLOR][COLOR=#303336]([/COLOR][COLOR=#7D2727]1[/COLOR][COLOR=#303336],[/COLOR][COLOR=#303336] s1[/COLOR][COLOR=#303336],[/COLOR][COLOR=#7D2727]" "[/COLOR][COLOR=#303336])[/COLOR][COLOR=#303336]
[/COLOR][COLOR=#101094]While[/COLOR][COLOR=#303336]([/COLOR][COLOR=#303336]pos [/COLOR][COLOR=#303336]<>[/COLOR][COLOR=#7D2727]0[/COLOR][COLOR=#303336])[/COLOR][COLOR=#303336]
s2 [/COLOR][COLOR=#303336]=[/COLOR][COLOR=#303336] s2 [/COLOR][COLOR=#303336]&[/COLOR][COLOR=#303336] Mid[/COLOR][COLOR=#303336]([/COLOR][COLOR=#303336]s1[/COLOR][COLOR=#303336],[/COLOR][COLOR=#7D2727]1[/COLOR][COLOR=#303336],[/COLOR][COLOR=#303336] pos [/COLOR][COLOR=#303336]-[/COLOR][COLOR=#7D2727]1[/COLOR][COLOR=#303336])[/COLOR][COLOR=#303336]&[/COLOR][COLOR=#7D2727]","[/COLOR][COLOR=#303336]
s1 [/COLOR][COLOR=#303336]=[/COLOR][COLOR=#303336] Mid[/COLOR][COLOR=#303336]([/COLOR][COLOR=#303336]s1[/COLOR][COLOR=#303336],[/COLOR][COLOR=#303336] pos [/COLOR][COLOR=#303336]+[/COLOR][COLOR=#7D2727]1[/COLOR][COLOR=#303336])[/COLOR][COLOR=#303336]
pos [/COLOR][COLOR=#303336]=[/COLOR][COLOR=#303336] InStr[/COLOR][COLOR=#303336]([/COLOR][COLOR=#7D2727]1[/COLOR][COLOR=#303336],[/COLOR][COLOR=#303336] s1[/COLOR][COLOR=#303336],[/COLOR][COLOR=#7D2727]" "[/COLOR][COLOR=#303336])[/COLOR][COLOR=#303336]
[/COLOR][COLOR=#101094]Wend[/COLOR][COLOR=#303336]
s2 [/COLOR][COLOR=#303336]=[/COLOR][COLOR=#303336] s2 [/COLOR][COLOR=#303336]&[/COLOR][COLOR=#303336] s1
ActiveSheet[/COLOR][COLOR=#303336].[/COLOR][COLOR=#303336]ActiveCell[/COLOR][COLOR=#303336].[/COLOR][COLOR=#303336]Value [/COLOR][COLOR=#303336]=[/COLOR][COLOR=#303336] s2
[/COLOR][COLOR=#101094]End[/COLOR][COLOR=#101094]Sub
[/COLOR]
Found this code online and need help make it do what I want.
I want replace the last comma with "and" instead of this replacing all spaces with comma .
There may be :
1. No word
2. Only one word
3. Only two words
4. More than two words.
So I want all those factors considered.
Thanks </code>