Consulting

Results 1 to 7 of 7

Thread: calculate only when macro has been enable.

  1. #1
    VBAX Tutor
    Joined
    Sep 2009
    Posts
    231
    Location

    calculate only when macro has been enable.

    Hi ,

    I am trying work out with the attached files where the calculation has been set to manual.

    And the file shall calculate only when the macro has been enable but not when disable as besides this there is a lot of check being done through VBA and if user click on the disable button and then the calculation is done it may have big different on the stock values.

    here is the code am trying since long :
    [VBA]
    Sub CALCULATION()


    Worksheets("HANDFLAT").Activate

    ' With Application
    ' .CALCULATIONfull
    ' .Iteration = True
    ' .CalculateBeforeSave = True
    ' End With
    Application.CalculateFullRebuild

    Application.CALCULATION = xlCalculationManual

    End Sub[/VBA]

    but the code seems not be working.

    I am also attaching part of the file to have an idea.

    many thanks for helping in advance.


    Attached Files Attached Files

  2. #2
    Administrator
    VP-Knowledge Base
    VBAX Grand Master mdmackillop's Avatar
    Joined
    May 2004
    Location
    Scotland
    Posts
    14,489
    Location
    The Activate line fails with me. try
    [VBA]Worksheets("HANDFLAT").Select[/VBA]
    MVP (Excel 2008-2010)

    Post a workbook with sample data and layout if you want a quicker solution.


    To help indent your macros try Smart Indent

    Please remember to mark threads 'Solved'

  3. #3
    VBAX Tutor
    Joined
    Sep 2009
    Posts
    231
    Location
    hi ,

    thanks it works on the handflat sheets.

    Can you help me further on how can i do it also for other sheets. Shall i code for all the sheets seperately.

    as the workbook will have approx. 14 sheets for control.

    thanks again for your help.

  4. #4
    Moderator VBAX Sage SamT's Avatar
    Joined
    Oct 2006
    Location
    Near Columbia
    Posts
    7,814
    Location
    [VBA]Sub Application_WindowActivate(ByVal Wb As Excel.Workbook, ByVal Wn As Excel.Window)
    Wb.Application.CALCULATION = xlCalculationManual
    End Sub[/VBA]
    I expect the student to do their homework and find all the errrors I leeve in.


    Please take the time to read the Forum FAQ

  5. #5
    VBAX Tutor
    Joined
    Sep 2009
    Posts
    231
    Location
    hi Sam,
    Sorry for the lateness

    I have not well understand on how to use the above code well.

    can you please explain me.

    many thanks.

  6. #6
    Moderator VBAX Sage SamT's Avatar
    Joined
    Oct 2006
    Location
    Near Columbia
    Posts
    7,814
    Location
    Vishal,

    You want workbook to calculate only when your Sub CALCULATION() Runs.

    Put this sub in ThisWorkbook CodePane for every workbook you want to force CalculationManual

    [VBA]Sub Application_WindowActivate(ByVal Wb As Excel.Workbook, ByVal Wn As Excel.Window)
    Wb.Application.CALCULATION = xlCalculationManual
    End Sub[/VBA]
    I expect the student to do their homework and find all the errrors I leeve in.


    Please take the time to read the Forum FAQ

  7. #7
    VBAX Tutor
    Joined
    Sep 2009
    Posts
    231
    Location
    ok thanks i try and revert

Posting Permissions

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