Results 1 to 10 of 10

Copying a VBA variable into the Clipboard

This is a discussion on Copying a VBA variable into the Clipboard within the Excel Questions forums, part of the Question Forums category; Maybe this is an easy question, but I don't know how to do this. I have a macro that copies ...

  1. #1
    New Member
    Join Date
    Jun 2002
    Location
    Philadelphia
    Posts
    46

    Default

    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.

  2. #2
    MrExcel MVP
    Join Date
    Feb 2002
    Location
    Bogota, Colombia
    Posts
    11,948

    Default

    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 ?
    Regards,

    Juan Pablo González
    http://www.juanpg.com

  3. #3
    New Member
    Join Date
    Jun 2002
    Location
    Philadelphia
    Posts
    46

    Default

    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.

  4. #4
    MrExcel MVP
    Join Date
    Feb 2002
    Location
    Bogota, Colombia
    Posts
    11,948

    Default

    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.
    Regards,

    Juan Pablo González
    http://www.juanpg.com

  5. #5
    Legend NateO's Avatar
    Join Date
    Feb 2002
    Location
    Minneapolis, Mn, USA
    Posts
    9,702

    Default

    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.

    Dim n 'first line in module

    Sub cpy()
    n = ActiveCell.Value
    End Sub

    Sub pste()
    ActiveCell.Value = n
    End Sub


    2.

    Sub otherway()
    Selection.Copy
    End Sub


    Good luck.

    _________________
    Cheers, Nate Oliver

    [ This Message was edited by: NateO on 2002-06-21 15:08 ]

  6. #6
    MrExcel MVP
    Join Date
    Feb 2002
    Location
    Bogota, Colombia
    Posts
    11,948

    Default

    Thanks Nate, and nice simple approach !
    Regards,

    Juan Pablo González
    http://www.juanpg.com

  7. #7
    New Member
    Join Date
    Jun 2002
    Location
    Philadelphia
    Posts
    46

    Default

    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

  8. #8
    New Member
    Join Date
    Jun 2002
    Location
    Philadelphia
    Posts
    46

    Default

    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.

    Dim n 'first line in module

    Sub cpy()
    n = ActiveCell.Value
    End Sub

    Sub pste()
    ActiveCell.Value = n
    End Sub


    2.

    Sub otherway()
    Selection.Copy
    End Sub

    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

  9. #9
    Legend NateO's Avatar
    Join Date
    Feb 2002
    Location
    Minneapolis, Mn, USA
    Posts
    9,702

    Default

    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:


    Dim n As Long

    Sub cpy()
    n = ActiveCell.Value
    End Sub

    Sub mssWn()
    MsgBox (n / 2)
    End Sub


    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, Nate Oliver

    [ This Message was edited by: NateO on 2002-06-23 15:05 ]

  10. #10
    MrExcel MVP
    Join Date
    Feb 2002
    Location
    Bogota, Colombia
    Posts
    11,948

    Default

    Did you check Chip's webpage ? he has some code to handle the clipboard.
    Regards,

    Juan Pablo González
    http://www.juanpg.com

Like this thread? Share it with others

Like this thread? Share it with others

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  


DMCA.com