Results 1 to 2 of 2

Thread: Copy/PasteSpecial without changing focus?

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    May 2004
    Location
    Right here
    Posts
    275

    Copy/PasteSpecial without changing focus?

    Hi all,

    I've got a bit of VBA code which basically copies the contents of 1 table and pastes the values only (not the formulas) into another table. I have this procedure linked to a button which is on a different part of the worksheet. The problem I am having is that whenever I press the button to run the macro, it does what it's supposed to do but it always changes the focus to the table i.e. the view on the worksheet moves to the table that has just had values pasted into it.

    If I change the macro so it's just a normal copy/paste function (so it also copies the formulas) the focus remains on the part of the worksheet with the button. It's only when I change the code to include the pastespecial function that the focus changes. Here is the normal copy/paste code:

    Code:
    Range("table1").Copy
        With ActiveSheet
            .Paste ("SA_Demand_Met")
        End With
    And here it is with the copy/pastespecial function:

    Code:
    Range("table1").Copy
        
        With Range("SA_Demand_Met")
            .PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
            :=False, Transpose:=False
        End With
    The problem is I don't see why the copy/pastespecial code keeps changing the focus. There is no 'select' function in there so why does it keep moving to the area of operations? Is there anyway I can prevent this?

    Cheers
    -Rob

  2. #2
    Fanatic Member VBAhack's Avatar
    Join Date
    Dec 2004
    Location
    Sector 000
    Posts
    617

    Re: Copy/PasteSpecial without changing focus?

    Not sure what you mean by focus, but I've used this in the past that may or may not help your situation.

    VB Code:
    1. Dim CurrentRange as Range
    2. set CurrentRange = selection() ' save current range
    3. ' do stuff
    4. CurrentRange.Select

    VBAhack

Posting Permissions

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



Click Here to Expand Forum to Full Width