View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.programming
quartz[_2_] quartz[_2_] is offline
external usenet poster
 
Posts: 441
Default How to copy to cashe?

Denis,

One method follows. Copy both the sub and the function below into a standard
code module. This assumes that each line of your data resides in one cell (or
column) - you didn't specify about this...
Anyway, select the cells containing your data first, then run the Sub
TestThis(). After it runs, the result is placed in the clipboard and you can
paste it from there.

Sub TestThis()

Dim rCell As Range
Dim sData As String
For Each rCell In Selection
If rCell.FormulaR1C1 < "" Then sData = sData & Left(rCell.FormulaR1C1,
5) & "|"
Next
sData = Left(sData, Len(sData) - 1)
Call ClipboardAddString(sData)
MsgBox sData
End Sub

Public Function ClipboardAddString(argString As String)
'REQUIRED: REFERENCE TO MICROSOFT FORMS 2.0 OBJECT LIBRARY
'PROGRAMMATICALLY PLACE DATA IN THE CLIPBOARD;
Dim objData As DataObject
Set objData = New DataObject
objData.SetText argString
objData.PutInClipboard
End Function

HTH.

"Denis Petrov" wrote:

Dear VBA gurus

I have data
11111, abc, xxx,
22222, def, yyy
33333, ghi, zzz

I need to create a VBA code to copy vlaue
11111|22222|33333 (yes, that exact format with |) to the cache so user can
Paste, please HELP!!!!

Thanks to all