Put Two values into Clipboard with VBA

vonguyenphu

New Member
Joined
May 26, 2019
Messages
29
I need to put value of 2 cells saying cell 'A1" and 'A2' into window's clipboard to use for other purpose

Dim obj as DataObject

Obj.SetText range("A1")
Obj.PutInClipboard
Obj.SetText left(range("A2"),4)
Obj.PutInClipboard

When i run code (f5), then opened window's clipboard, it only saved the second (
left(range("A2"),4)) and didn't include A1
However when i run via F8 in source code step by step, it saved both values.
Can anyone help me put two values into clipboard when running by F5?
 

Excel Facts

How to find 2nd largest value in a column?
MAX finds the largest value. =LARGE(A:A,2) will find the second largest. =SMALL(A:A,3) will find the third smallest
Try this

Code:
Dim obj As DataObject


obj.SetText Range("A1").Value & "; " & Left(Range("A2").Value, 4)
obj.PutInClipboard
 
Upvote 0
I ran into issues on one of our users machines with loading the clipboard. We had to approach with a late-binding method.

Code:
Dim dObj As Object

Set dObj = CreateObject("new:{1C3B4210-F441-11CE-B9EA-00AA006B1A69}")
dObj.SetText Range("A1").Value & "; " & Left(Range("A2").Value, 4)
dObj.PutInClipboard
Set dObj = Nothing
 
Upvote 0
Thks guys, but it still saved one value. The difference is the new value is concatenated from 2 old strings. i need 2 values so i can easily copy in other programs
 
Upvote 0
Thks guys, but it still saved one value. The difference is the new value is concatenated from 2 old strings. i need 2 values so i can easily copy in other programs


Before you must clean the memory and raise the concatenated value, you have a value but when you read it you should separate it by ; and in that way you will have 2 values.
 
Upvote 0

Forum statistics

Threads
1,215,575
Messages
6,125,628
Members
449,241
Latest member
NoniJ

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