Consulting

Results 1 to 7 of 7

Thread: When to Use "Application.CutCopyMode" Statement

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1

    When to Use "Application.CutCopyMode" Statement

    Will someone give me a short tutorial about when to use the statement "Application.CutCopyMode = "? It would seem that maybe it should be a standard statement at the end of most macros that do any copying, but I'm just guessing.

  2. #2
    Moderator VBAX Guru Simon Lloyd's Avatar
    Joined
    Sep 2005
    Location
    UK
    Posts
    3,003
    Location
    I don't know about tutorial as i'm no guru but here goes:
    this first copy 'n' paste is how you would expect to perform the action manually, i.e all the clicks or keystrokes[VBA]
    Sub Copy1()
    Range("A1").Select
    Selection.Copy
    Range("B1").Select
    ActiveSheet.Paste
    Application.CutCopyMode = False
    End Sub
    [/VBA]thsi next one is exactly the same as the first but performed by VBA and has a specific destination whereas the first did not until you clicked it[VBA]Sub Copy2()
    Range("A1").Copy Destination:=Range("B2")
    End Sub[/VBA]the next is for copying a component of the cell, i.e the format or value ...etc, here again there is no destination cell until you click it[VBA]
    Sub Copy3()
    Range("A1").Select
    Selection.Copy
    Range("E3").Select
    Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
    :=False, Transpose:=False
    Application.CutCopyMode = False
    End Sub[/VBA]here's the same in a shortened version but although we have designated the cell straight away the following actions are only part of a copy and therefore copyMode is still in place for you to paste another component[VBA]Sub Copy4()
    Range("A1").Copy
    Range("E6").PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
    :=False, Transpose:=False
    End Sub[/VBA]in short using "Application.CutCopyMode=" clears excels memory so nothing further can be pasted from that selection.

    I may not be dead accurate with the explanation and someone may put me right but its as near as damn it!
    Regards,
    Simon
    Please read this before cross posting!
    In the unlikely event you didn't get your answer here try Microsoft Office Discussion @ The Code Cage
    If I have seen further it is by standing on the shoulders of giants.
    Isaac Newton, Letter to Robert Hooke, February 5, 1675 English mathematician & physicist (1642 - 1727)

  3. #3
    Thanx for the reply, Simon. Basically, one might say that if you have done a lot of copying in your macro, then you can clear all the memory used by the copy operations by executing CutCopyMode. If copying just small amounts, then there's no real advantage to using CutCopyMode.
    Can I assume that CutCopyMode is essentially useless if no copying has been done in the macro? I mean, is it strictly related to copying processes and no others?

  4. #4
    VBAX Master Norie's Avatar
    Joined
    Jan 2005
    Location
    Stirling, Scotland
    Posts
    1,831
    Location
    Cyberdude

    There might not be any need to use it anywhere.

    It really depends what you are doing.

    If you are using Paste or PasteSpecial then you probably should be using it.

  5. #5
    Moderator VBAX Guru Simon Lloyd's Avatar
    Joined
    Sep 2005
    Location
    UK
    Posts
    3,003
    Location
    Purely copying!
    Regards,
    Simon
    Please read this before cross posting!
    In the unlikely event you didn't get your answer here try Microsoft Office Discussion @ The Code Cage
    If I have seen further it is by standing on the shoulders of giants.
    Isaac Newton, Letter to Robert Hooke, February 5, 1675 English mathematician & physicist (1642 - 1727)

  6. #6
    VBAX Tutor david000's Avatar
    Joined
    Mar 2007
    Location
    Chicago
    Posts
    276
    Location
    There is one ultra obscure reason to check that you cleared the clipboard, but I don?t have the example anymore.

    Anybody that has John Walkenbach?s aka J-Walks Pup2000 (old) AddIn with source code can see this. He used a logo that did not clear the clipboard (how it got there is the bug) if you loaded the right-click menu shortcuts.

    I don?t have it on me but I did email J-Walk about this issue and he told me how to fix it (I was so in awe of him at the time).

  7. #7
    Administrator
    VP-Knowledge Base
    VBAX Grand Master mdmackillop's Avatar
    Joined
    May 2004
    Location
    Scotland
    Posts
    14,489
    Location
    I would use it even after small "copies" to avoid unexpected results.

    Edit:
    I had an issue in some code where the clipboard would not clear. As a workaround I used this to put a null string there.
    Cells(Rows.Count,1).Copy
    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'

Posting Permissions

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