+ Reply to Thread
Results 1 to 5 of 5

Loop to retrieve data from different sheet

  1. #1
    Registered User
    Join Date
    02-13-2012
    Location
    NYC
    MS-Off Ver
    Excel 2003
    Posts
    39

    Loop to retrieve data from different sheet

    Hello,

    I was wondering if you could find a solution to the case below.

    In the following example, I first start from a loop in 1 single sheet (that works) and then modify it to write the results from a loop into a different sheet (what doesn't work). See loop9 and loop10 below respectively.
    If you find however another way to perform this code, in a simpler way, please let me know. The idea is to perform this task for over 65K lines.

    In 1 single sheet, and working:

    Please Login or Register  to view this content.
    To retrieve data from sheet 1 and put results in sheet 'Avg' however, the result does not work. I have tried various versions of what I put below. I have tried to simplify by defining a function 'AverageFor4' that calculates average of columns A & B in column C per 2 lines (so an average of 4 numbers). I want to write the results on sheet 'Avg', whereas the data are on sheet 1.

    Thank you.

    Please Login or Register  to view this content.
    Last edited by zeno1; 02-13-2012 at 05:47 PM.

  2. #2
    Valued Forum Contributor
    Join Date
    12-05-2011
    Location
    Toronto, Canada
    MS-Off Ver
    Excel 2010 & 2013
    Posts
    308

    Re: Excel VBA 2003: loop to retrieve data from different sheet

    Hi zeno

    Please correct your post, as outlined above by TMShucks. Add [ c od e ] [/ c o d e ] (no spaces) around your code.

    Some pointers:
    ActiveCell is on the current open worksheet. If you are in your first sheet and trying to modify the AVG sheet, you will need to give a cell reference. You could use a variable to keep track of which row you are in. e.g.
    Please Login or Register  to view this content.
    Probably best to move your Dim statement outside of the loop. i.e.
    Please Login or Register  to view this content.
    You don't appear to have set ValueAvg to anything on the first time it is written to a cell. It is therefore empty and the cell you are writing will also be empty.

    Best regards, Rob.
    Last edited by rscsmith; 02-13-2012 at 07:34 PM.

  3. #3
    Registered User
    Join Date
    02-13-2012
    Location
    NYC
    MS-Off Ver
    Excel 2003
    Posts
    39

    Re: Excel VBA 2003: loop to retrieve data from different sheet

    Rob,
    Thanks for your comments.
    I made modifications to get the following:

    Please Login or Register  to view this content.

  4. #4
    Valued Forum Contributor
    Join Date
    12-05-2011
    Location
    Toronto, Canada
    MS-Off Ver
    Excel 2010 & 2013
    Posts
    308

    Re: Excel VBA 2003: loop to retrieve data from different sheet

    Hi zeno

    Looks ok. Any problems?

    To avoid lots of screens flickering around and to speed things up, you could add:
    Please Login or Register  to view this content.
    Be warned - if the code crashes you can end up with Excel appearing unresponsive until you go to the VBE and enter "Application.ScreenUpdating = True" in the immediate window. It is good to add error trapping when you use this method to avoid this scenario.

    Best regards, Rob.

  5. #5
    Registered User
    Join Date
    02-13-2012
    Location
    NYC
    MS-Off Ver
    Excel 2003
    Posts
    39

    Re: Excel VBA 2003: loop to retrieve data from different sheet

    Rob,

    Thanks so much for your feedback.
    It helps a lot.

    Zeno

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Tags for this Thread

Bookmarks

Posting Permissions

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

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1