saiyamvora13
New Member
- Joined
- Apr 3, 2015
- Messages
- 32
Hello,
Here is the Macro that I am using
Sub Selected_to_Comma_Separated()
Dim MyRange As Range
Dim NewRange As Range
Dim arr
Dim clip As MSForms.DataObject
For Each MyRange In Selection
If MyRange.Value <> "" Then
MyRange.Value = Chr(39) & Chr(39) & MyRange.Value & Chr(39)
End If
Next MyRange
Set NewRange = Selection
arr = Join(Application.Transpose(NewRange.Value), ",")
Set clip = New MSForms.DataObject
clip.SetText arr
clip.PutInClipboard
MsgBox "Copied to clipboard: " & Chr$(10) & arr
End Sub
What it does:
Anything that is selected on the excel sheet, it will add quotations in the start(') and end(') and it will add a comma (,) and then copy it to the clipboard
Example (al033j) will become ('al033f',)
Issue is that if I press the macro button the second time, the selection now becomes (''al033f'',)
If i press it 3rd time it becomes ('''al033f''',)
If I press it 4th time it becomes (''''al033f'''',)
This keeps going on.
Is there anyway for me to keep it at ('al033f',) no matter how many times I press the button?
Thank you for all your help
Here is the Macro that I am using
Sub Selected_to_Comma_Separated()
Dim MyRange As Range
Dim NewRange As Range
Dim arr
Dim clip As MSForms.DataObject
For Each MyRange In Selection
If MyRange.Value <> "" Then
MyRange.Value = Chr(39) & Chr(39) & MyRange.Value & Chr(39)
End If
Next MyRange
Set NewRange = Selection
arr = Join(Application.Transpose(NewRange.Value), ",")
Set clip = New MSForms.DataObject
clip.SetText arr
clip.PutInClipboard
MsgBox "Copied to clipboard: " & Chr$(10) & arr
End Sub
What it does:
Anything that is selected on the excel sheet, it will add quotations in the start(') and end(') and it will add a comma (,) and then copy it to the clipboard
Example (al033j) will become ('al033f',)
Issue is that if I press the macro button the second time, the selection now becomes (''al033f'',)
If i press it 3rd time it becomes ('''al033f''',)
If I press it 4th time it becomes (''''al033f'''',)
This keeps going on.
Is there anyway for me to keep it at ('al033f',) no matter how many times I press the button?
Thank you for all your help