Copying a VBA variable into the Clipboard

Warminster

New Member
Joined
Jun 12, 2002
Messages
46
Maybe this is an easy question, but I don't know how to do this.

I have a macro that copies a cell, and then uses VBA to modify that information. I'd like to be able to put that information into the clipboard, so that I can paste the information into any cell that I choose.

How do I copy my variable into the clipboard.
 

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
Well... I know Chip has some code to put and read stuff from the Clipboard (www.cpearson.com) BUT... if it's a variable, you could just do this:

MyVar = Range("A1").Value
MyVar = MyVar * 5 + 50
Range("A2") = MyVar

Or am I way off of what you need ?
 
Upvote 0
Ah.. I see, something like run a macro to put the variable in the clipboard, and you can use Control V to store it in the cell ?

Mhmm... let me think about it.
 
Upvote 0
Wow, kudos on the manners sir, nice to see a helpful guy like Juan barked at, you weren't raised in a barn by chance?

Here's two ways of doing this.

1.<pre>
Dim n 'first line in module

Sub cpy()
n = ActiveCell.Value
End Sub

Sub pste()
ActiveCell.Value = n
End Sub</pre>

2.<pre>
Sub otherway()
Selection.Copy
End Sub</pre>

Good luck.

_________________
Cheers,<font size=+2><font color="red"> Nate<font color="blue"> Oliver</font></font></font>
This message was edited by NateO on 2002-06-21 15:08
 
Upvote 0
On 2002-06-21 14:51, Juan Pablo G. wrote:
Ah.. I see, something like run a macro to put the variable in the clipboard, and you can use Control V to store it in the cell ?

Mhmm... let me think about it.

Thats exactly what I am looking for. I don't want to have to select the destination cell in my code. I want to have the ability to paste the cell to another cell at a later time. I don't know if that cell will be in the same sheet, same workbook, etc. I want to be able to copy the cell, have my code perform an action on it, and store it on the clipboard. If I have to have my code post the result, it defeats the purpose I am trying to achieve.

Thanks
 
Upvote 0
On 2002-06-21 15:04, NateO wrote:
Wow, kudos on the manners sir, nice to see a helpful guy like Juan barked at, you weren't raised in a barn by chance?

I'm sorry, what? Can you please quote the line where I "barked" at Juan? I certainly did not intend to be rude, and apologize if I came off that way. After rereading the thread several times, I can only find one statement that is offensive or objectional in any way. Yours.

Here's two ways of doing this.
1.
<pre>
Dim n 'first line in module

Sub cpy()
n = ActiveCell.Value
End Sub

Sub pste()
ActiveCell.Value = n
End Sub</pre>

2.
<pre>
Sub otherway()
Selection.Copy
End Sub</pre>

Neither of your two suggestions quite does what I want. Option 1 requires my code to paste the value. This limits my flexibility as I am no longer able to paste anywhere.

Option 2 does put the value into the clipboard, but does not allow me to perform any modifications to the value before it is put there.

I apologize that my original post was unclear on exactly what I was trying to do. I appreciate all your help in trying to figure this out.

Thanks
 
Upvote 0
On 2002-06-21 14:46, Warminster wrote:
i don't want to have to specify the range. I want to be able to use this to copy and then paste to anywhere.

I guess this didn't strike me as curteous.

It depends what type of data your copying is, if it's numeric, dim your variable as such, you don't need to paste the variable:<pre>
Dim n As Long

Sub cpy()
n = ActiveCell.Value
End Sub

Sub mssWn()
MsgBox (n / 2)
End Sub<pre>

You can paste it later with the code above, it's stored, not sure why you ran the pst() procedure right away....Just an example. Hope this helps.

_________________
Cheers,<font size=+2><font color="red"> Nate<font color="blue"> Oliver</font></font></font>
This message was edited by NateO on 2002-06-23 15:05
 
Upvote 0

Forum statistics

Threads
1,223,671
Messages
6,173,737
Members
452,533
Latest member
Alex19k

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