Results 1 to 4 of 4

Thread: *resolved* Pasting results into a dynamic range on a different worksheet

Threaded View

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

    *resolved* Pasting results into a dynamic range on a different worksheet

    I have set up a spreadsheet in order to run some macro-based calculations, basically a simulation of a water network. It that has two worksheets. One is "Global Settings" where the user enters some basic settings and one called "Results" which records the outputs of the simulations. For various reasons I have had to create a variable which stores a dynamic range which changes every iteration of the simulation. This dynamic range then has a specific value placed in it (every cell) per iteration of the simulation. Code as below:

    Code:
    'create the range that will have the average flow values pasted in to it
    Set paste_range = Range(Cells(row_number, 3), Cells(row_number + event_duration - 1, 3)) 
    
    'paste the average_flow value in to the dynamic range
    paste_range.Value = average_flow
    Now the setting up of the dynamic range seems to work okay. The problem I am having is that it ALWAYS pastes the values into the dynamic range on to GLOBAL SETTINGS worksheet, where the simulation is run from, and I need them pasting in to the RESULTS worksheet. The reason I think it does this is that the code shown above is executed whilst the Global Settings worksheet is activated. For some reason I think the paste_range variable I created to hold the dynamic range becomes linked to the Global Settings worksheet.

    I have tried creating the range so it is linked to the Results worksheet without success (I don't know the syntax to do this, or even if it's possible). Also tried using With Sheets ("Results") and tried getting it to paste the values that way but again it doesn't work and they always end up on the Global Settings worksheet.

    Any ideas how I can get the values to paste in to the right worksheet?

    Thanks
    -Rob

    Ps - I should add that I have also tried the following but it does not worK:

    Code:
    Set paste_range = Sheets("Results").Range(Cells(row_number, 3), Cells(row_number + event_duration - 1, 3))
    I would have expected this to work but I get a "application-defined or object-defined error", which is strange because I thought this approach would work.
    Last edited by TheRobster; Aug 26th, 2012 at 03:23 AM. Reason: Resolved
    http://www.sudsolutions.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
  •