Consulting

Results 1 to 4 of 4

Thread: Solved: Problem with For Loop

  1. #1

    Solved: Problem with For Loop

    Hi i have an excel workbook with many sheets some of which have table formulas. Pressing F9 takes a long time to calculate. I think VBA can help but i am not sure why the following code would not work (doesnt loop through the next sheets after the first).


    Sub Calculate()

    Dim MySheet As Worksheet
    Dim Counter As Integer


    For Each MySheet In ActiveWorkbook.Sheets
    ActiveSheet.Calculate
    Next MySheet


    End Sub

    Appreciate any help

  2. #2
    VBAX Mentor
    Joined
    Dec 2007
    Posts
    462
    Location
    what error(s) are you getting and/or what is happening when you say this isn't working?

  3. #3
    Hi:

    First point with regards to your code: You don't want to say ActiveSheet.Calculate. The code WILL go through all the sheets in the workbook, but only the ACTIVE sheet will be recalculated. You want the code changed to:

    For Each MySheet In ActiveWorkbook.Sheets
    MySheet.Calculate
    Next MySheet

    Hopefully you can follow that explanation, if not, please let me know and I will elaborate further.

    Second point with regards to calculation: Choosing calculate through vba will not make your spreadsheet calculate faster than F9.

    You need to examine your spreadsheet regarding the organization of data and the functions used. Especially recursive functions (array formulas etc...) and for redundant formulas.
    ___________________________________
    g-
    gwkenny@Fin-ITSolutions.com
    ___________________________________

  4. #4
    Thanks. it's working now after i made the changes you suggested

Posting Permissions

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