Consulting

Results 1 to 7 of 7

Thread: Copy - Do Procedure - Paste

  1. #1

    Copy - Do Procedure - Paste

    I am trying to do what should be very simple.

    I am trying to copy a range of cells to the clipboard, then delete the range, run some code to assess the impact this has had on dependent formulas, and the paste back the original text, values, and formulas.

    I would expect the simplified code to look something like this.

    Sub GOGO()
    Selection.Copy
    Selection.ClearContents
    ' Run my other code here
    Selection.Paste ' Paste in original values, text and formulas.
    End Sub

    I do not think the GetFromClipboard, and PutInClipboard procedures will help me, am I wrong?

  2. #2
    Hi

    My thought would be that it would depend on the amount of processing, but you will probably lose the data from the clipboard. If you have a fixed number of cells, then it may pay to store those details in an array in the program, clear out the existing data, process, then restore the original data from the stored array.

    HTH

    Tony

  3. #3
    Administrator
    VP-Knowledge Base
    VBAX Grand Master mdmackillop's Avatar
    Joined
    May 2004
    Location
    Scotland
    Posts
    14,489
    Location
    From the sound of it, you might be best to paste immediately in a temporary location, then cut and paste back after your other code is run.
    Regards
    MD
    MVP (Excel 2008-2010)

    Post a workbook with sample data and layout if you want a quicker solution.


    To help indent your macros try Smart Indent

    Please remember to mark threads 'Solved'

  4. #4
    That is my temporary solution - to store the data in an array, however I may be required to store serveral thousand cells sometimes. I am able to paste manually from the toolbar - I must be able to do the same with VBA.

  5. #5
    VBAX Master Norie's Avatar
    Joined
    Jan 2005
    Location
    Stirling, Scotland
    Posts
    1,831
    Location
    Instead of Copy then ClearContents try using Cut.

  6. #6
    There is no difference between that and copy. I still have exactly the same problem. I want to be able to paste from the clipboard. I would really like to be able to paste the nth entry from the clipboard.

  7. #7
    VBAX Master TonyJollans's Avatar
    Joined
    May 2004
    Location
    Norfolk, England
    Posts
    2,291
    Location
    I think Malcolm is correct, but ...

    Depending on what you're doing, could you use Scenarios rather than doing your own thing?
    Enjoy,
    Tony

    ---------------------------------------------------------------
    Give a man a fish and he'll eat for a day.
    Teach him how to fish and he'll sit in a boat and drink beer all day.

    I'm (slowly) building my own site: www.WordArticles.com

Posting Permissions

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