Results 1 to 4 of 4

Thread: Excel VBA - copy/paste special to another worksheet and descending rows

  1. #1
    Addicted Member
    Join Date
    May 04
    Location
    Right here
    Posts
    185

    Excel VBA - copy/paste special to another worksheet and descending rows

    Hi all,

    I have two worksheets in a workbook, one called Calculations and one called Results. Calculations has a bunch of equations for running some data analysis that iterates through data sets using VBA code and results from each iteration are always output in cells A1:Z1. Results from each iteration need to be stored in the worksheet called Results.

    Basically I need some way of copying cells A1:Z1 from Calculations worksheet to Results but each paste operation has to be below the last, e.g.

    iteration 1: copy/pastespecial values only A1:Z1 from Calculations to A1:Z1 in Results
    iteration 2: copy/pastespecial values only A1:Z1 from Calculations to A2:Z2 in Results
    iteration 2: copy/pastespecial values only A1:Z1 from Calculations to A3:Z3 in Results

    Etc etc. This process continues for some amount of iterations that is user-defined (I have this bit sorted using a variable).

    I imagine there's some combination of pastespecial and xlup commands that can do this but I've tried to write the code without success. Can anyone offer any help?

    Thanks in advance.
    -Rob
    Last edited by TheRobster; Aug 13th, 2012 at 03:48 PM.
    http://www.sudsolutions.com

  2. #2
    New Member
    Join Date
    Aug 12
    Location
    Wisconsin, USA
    Posts
    8

    Re: Excel VBA - copy/paste special to another worksheet and descending rows

    If you like, I could try to help. Can you share the file so that I can take a look at it for you? Or post a screenshot of what we are looking at?

  3. #3
    Addicted Member
    Join Date
    May 04
    Location
    Right here
    Posts
    185

    Re: Excel VBA - copy/paste special to another worksheet and descending rows

    Well I got something that works but it isn't very elegant:

    Code:
    Range("A1:Z1").Copy
    
    With Sheets("Results")
        .Range("A99999").End(xlUp).Offset(1, 0).PasteSpecial Paste:=xlPasteValues
    End With
    This is run with worksheet Simulation selected. However when pasting results to the Results worksheet it always selects it, then jumps back to worksheet Simulation. Is there anyway of stopping it doing this? It shouldn't have to select a worksheet to copy results to it surely?
    http://www.sudsolutions.com

  4. #4
    New Member
    Join Date
    Aug 12
    Location
    Wisconsin, USA
    Posts
    8

    Re: Excel VBA - copy/paste special to another worksheet and descending rows

    What event handler initiates the function?

    Is this what you are looking for??

    Code:
    Range("A1:Z1").Copy
    
    With Sheets("Results")
        .Range("A99999").End(xlUp).Offset(1, 0).PasteSpecial Paste:=xlPasteValues
    End With
        Sheets("Results").Select
    Last edited by kobie2402; Aug 14th, 2012 at 11:17 PM.

Posting Permissions

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