Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 24
Default Losing Quotes

Hi All,
I often have a need to create a list of quote encased, comma separated
values and generally they are in or can be created in Excel. So, I
created a macro to do the hard work for me, so I didn't have to create
formulas every time I wanted to do this.
I wrote the following code and it works fine except the very first
element loses the quotes. Perhaps I highlight:

Jan
Feb
Mar

I want to be able to paste “Jan”, “Feb”, “Mar”
but, it’s coming back as Jan, “Feb”, “Mar”
The debug.print statement works fine, but putting it on the clipboard
messes it up. Any suggestions?

Thanks!

Sub camBuildString()
''Take the highlighted range and make it into a list of comma
separated values
Dim strQt As String, strOut As String, cell As Range
strQt = """": strOut = ""
For Each cell In Application.Selection
If Not IsEmpty(cell.Value) Then
strOut = strOut & strQt & cell.Value & strQt & ", "
End If
Next
Debug.Print (Left(strOut, Len(strOut) - 2))
'PutOnClipboard (Left(strOut, Len(strOut) - 2))
PutOnClipboard strOut
End Sub
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35,218
Default Losing Quotes

This worked for me:

Option Explicit
Sub camBuildString()

Dim DataObj As MSForms.DataObject

'Take the highlighted range and make it into a list of
'comma separated Values

Dim strQt As String
Dim strOut As String
Dim cell As Range

Set DataObj = New MSForms.DataObject

strQt = """" 'or just chr(34)
strOut = ""

For Each cell In Application.Selection
If Not IsEmpty(cell.Value) Then
strOut = strOut & strQt & cell.Value & strQt & ", "
End If
Next cell


DataObj.SetText Left(strOut, Len(strOut) - Len(", "))
DataObj.PutInClipboard

End Sub

Chip Pearson has lots of notes:
http://www.cpearson.com/excel/Clipboard.aspx

ps. If it's reall CSV, then I wouldn't include the additional space character
in the delimiter.

mcescher wrote:

Hi All,
I often have a need to create a list of quote encased, comma separated
values and generally they are in or can be created in Excel. So, I
created a macro to do the hard work for me, so I didn't have to create
formulas every time I wanted to do this.
I wrote the following code and it works fine except the very first
element loses the quotes. Perhaps I highlight:

Jan
Feb
Mar

I want to be able to paste “Jan”, “Feb”, “Mar”
but, it’s coming back as Jan, “Feb”, “Mar”
The debug.print statement works fine, but putting it on the clipboard
messes it up. Any suggestions?

Thanks!

Sub camBuildString()
''Take the highlighted range and make it into a list of comma
separated values
Dim strQt As String, strOut As String, cell As Range
strQt = """": strOut = ""
For Each cell In Application.Selection
If Not IsEmpty(cell.Value) Then
strOut = strOut & strQt & cell.Value & strQt & ", "
End If
Next
Debug.Print (Left(strOut, Len(strOut) - 2))
'PutOnClipboard (Left(strOut, Len(strOut) - 2))
PutOnClipboard strOut
End Sub


--

Dave Peterson
  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 24
Default Losing Quotes

On Dec 30, 11:07*am, Dave Peterson wrote:
This worked for me:

Option Explicit
Sub camBuildString()

* * Dim DataObj As MSForms.DataObject

* * 'Take the highlighted range and make it into a list of
* * 'comma separated Values

* * Dim strQt As String
* * Dim strOut As String
* * Dim cell As Range

* * Set DataObj = New MSForms.DataObject

* * strQt = """" 'or just chr(34)
* * strOut = ""

* * For Each cell In Application.Selection
* * * * If Not IsEmpty(cell.Value) Then
* * * * * * strOut = strOut & strQt & cell.Value & strQt & ", "
* * * * End If
* * Next cell

* * DataObj.SetText Left(strOut, Len(strOut) - Len(", "))
* * DataObj.PutInClipboard

End Sub

Chip Pearson has lots of notes:http://www.cpearson.com/excel/Clipboard.aspx

ps. *If it's reall CSV, then I wouldn't include the additional space character
in the delimiter.





mcescher wrote:

Hi All,
I often have a need to create a list of quote encased, comma separated
values and generally they are in or can be created in Excel. *So, I
created a macro to do the hard work for me, so I didn't have to create
formulas every time I wanted to do this.
I wrote the following code and it works fine except the very first
element loses the quotes. *Perhaps I highlight:


Jan
Feb
Mar


I want to be able to paste Jan , Feb , Mar
but, it s coming back as * Jan, Feb , Mar
The debug.print statement works fine, but putting it on the clipboard
messes it up. *Any suggestions?


Thanks!


Sub camBuildString()
''Take the highlighted range and make it into a list of comma
separated values
* Dim strQt As String, strOut As String, cell As Range
* strQt = """": strOut = ""
* For Each cell In Application.Selection
* * If Not IsEmpty(cell.Value) Then
* * * strOut = strOut & strQt & cell.Value & strQt & ", "
* * End If
* Next
* Debug.Print (Left(strOut, Len(strOut) - 2))
* 'PutOnClipboard (Left(strOut, Len(strOut) - 2))
* PutOnClipboard strOut
End Sub


--

Dave Peterson- Hide quoted text -

- Show quoted text -

Well, I thank you for your help, and I figured it out. When I pasted
your code in, that gave me the same results when I pasted into Excel.
But when I pasted into Notepad, it worked fine from either piece of
code. Must be Excel removing the quotes when I paste.

Also, thanks for the link, lots of good stuff there.

Thanks again,
Chris M.
Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Losing Data Jenny B. Excel Discussion (Misc queries) 2 January 31st 08 06:52 PM
change straight quotes to curly quotes callico Excel Discussion (Misc queries) 2 June 22nd 07 10:23 PM
How do i get historical stock quotes using MSN Money Stock Quotes Ash Excel Discussion (Misc queries) 0 May 11th 06 03:26 AM
Losing the #DIV/0! mevetts Excel Worksheet Functions 4 January 8th 06 09:34 PM
losing arrays mike Excel Programming 1 February 17th 04 11:58 PM


All times are GMT +1. The time now is 10:58 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"