+ Reply to Thread
Results 1 to 17 of 17

Can't turn autocalculate back on.

Hybrid View

thinlizzy Can't turn autocalculate back... 06-27-2012, 03:58 PM
oeldere Re: Can turn autocalculate... 06-27-2012, 04:07 PM
thinlizzy Re: Can turn autocalculate... 06-27-2012, 04:12 PM
oeldere Re: Can turn autocalculate... 06-27-2012, 04:16 PM
thinlizzy Re: Can turn autocalculate... 06-27-2012, 04:20 PM
oeldere Re: Can turn autocalculate... 06-27-2012, 04:26 PM
NBVC Re: Can turn autocalculate... 06-27-2012, 04:31 PM
thinlizzy Re: Can turn autocalculate... 06-27-2012, 04:32 PM
NBVC Re: Can turn autocalculate... 06-27-2012, 04:36 PM
thinlizzy Re: Can turn autocalculate... 06-27-2012, 04:31 PM
tigeravatar Re: Can turn autocalculate... 06-27-2012, 04:39 PM
thinlizzy Re: Can't turn autocalculate... 06-27-2012, 04:50 PM
tigeravatar Re: Can't turn autocalculate... 06-27-2012, 04:54 PM
thinlizzy Re: Can't turn autocalculate... 06-27-2012, 05:01 PM
tigeravatar Re: Can't turn autocalculate... 06-27-2012, 05:12 PM
thinlizzy Re: Can't turn autocalculate... 06-27-2012, 05:15 PM
tigeravatar Re: Can't turn autocalculate... 06-27-2012, 05:18 PM
  1. #1
    Registered User
    Join Date
    06-27-2012
    Location
    Indianapolis, IN
    MS-Off Ver
    Excel 2010
    Posts
    8

    Can't turn autocalculate back on.

    Hi guys, I am really new to vba. I managed to piece together the below macro but I can't seem to get autocalculate to turn back on and would appreciate some help.
    Sub testing()
    Application.Calculation = xlCalculationManual
    Dim FilesToOpen
       Dim x As Integer
       On Error GoTo ErrHandler
       Application.ScreenUpdating = False
       FilesToOpen = Application.GetOpenFilename _
         (FileFilter:="Microsoft Excel Files (*.xls), *.xls", _
         MultiSelect:=True, Title:="Select Short Term")
    
       If TypeName(FilesToOpen) = "Boolean" Then
           MsgBox "No Files were selected"
           GoTo ExitHandler
       End If
      x = 1
      Dim wkb As Workbook
      Dim wks As Worksheet
      Application.DisplayAlerts = False
      While x <= UBound(FilesToOpen)
          Set wkb = Workbooks.Open(FilesToOpen(x))
          On Error Resume Next
          On Error GoTo ErrHandler
          Cells.Copy
            ThisWorkbook.Activate
            Sheets("Short Term").Activate
            Range("A1").Select
            ActiveSheet.Paste
             wkb.Close False
          x = x + 1
      Wend
      Application.DisplayAlerts = True
    
       FilesToOpen = Application.GetOpenFilename _
         (FileFilter:="Microsoft Excel Files (*.xls), *.xls", _
         MultiSelect:=True, Title:="Select Term")
       If TypeName(FilesToOpen) = "Boolean" Then
           MsgBox "No Files were selected"
           GoTo ExitHandler
       End If
      x = 1
        Application.DisplayAlerts = False
      While x <= UBound(FilesToOpen)
          Set wkb = Workbooks.Open(FilesToOpen(x))
          On Error Resume Next
          On Error GoTo ErrHandler
          Cells.Copy
            ThisWorkbook.Activate
            Sheets("term").Activate
            Range("A1").Select
            ActiveSheet.Paste
             wkb.Close False
          x = x + 1
      Wend
      Application.DisplayAlerts = True
       FilesToOpen = Application.GetOpenFilename _
         (FileFilter:="Microsoft Excel Files (*.xls), *.xls", _
         MultiSelect:=True, Title:="Select GSE-TLGP")
       If TypeName(FilesToOpen) = "Boolean" Then
           MsgBox "No Files were selected"
           GoTo ExitHandler
       End If
      x = 1
        Application.DisplayAlerts = False
      While x <= UBound(FilesToOpen)
          Set wkb = Workbooks.Open(FilesToOpen(x))
          On Error Resume Next
          On Error GoTo ErrHandler
          Cells.Copy
            ThisWorkbook.Activate
            Sheets("GSE-TLGP").Activate
            Range("A1").Select
            ActiveSheet.Paste
             wkb.Close False
          x = x + 1
          Wend
    rename
    
    Application.DisplayAlerts = True
    ExitHandler:
    
       Application.ScreenUpdating = True
       Exit Sub
    ErrHandler:
       MsgBox Err.Description
       Resume ExitHandler
    
         On Error GoTo ErrHandler
    
    
    End Sub
    Last edited by thinlizzy; 06-27-2012 at 05:21 PM. Reason: code tags

  2. #2
    Forum Expert
    Join Date
    05-30-2012
    Location
    The Netherlands
    MS-Off Ver
    Office 365
    Posts
    14,987

    Re: Can turn autocalculate back on.

    With a recorded macro I get this line.

    You add it before End Sub.

    Application.Calculation = xlAutomatic
    Notice my main language is not English.

    I appreciate it, if you reply on my solution.

    If you are satisfied with the solution, please mark the question solved.

    You can add reputation by clicking on the star * add reputation.

  3. #3
    Registered User
    Join Date
    06-27-2012
    Location
    Indianapolis, IN
    MS-Off Ver
    Excel 2010
    Posts
    8

    Re: Can turn autocalculate back on.

    I tried that and when the macro ran it still didn't turn on Autocalculate. I am not sure

  4. #4
    Forum Expert
    Join Date
    05-30-2012
    Location
    The Netherlands
    MS-Off Ver
    Office 365
    Posts
    14,987

    Re: Can turn autocalculate back on.

    And if you put the code above?

    On Error GoTo ErrHandler
    I'm not a VBA expert, but the code should work.

    If not, wait for other to react.

  5. #5
    Registered User
    Join Date
    06-27-2012
    Location
    Indianapolis, IN
    MS-Off Ver
    Excel 2010
    Posts
    8

    Re: Can turn autocalculate back on.

    Yeah, I pretty much tried placing it everywhere with no success. I need autocalculate to stay turned off until the sub macro rename runs.
    Thanks for the attempt though.

  6. #6
    Forum Expert
    Join Date
    05-30-2012
    Location
    The Netherlands
    MS-Off Ver
    Office 365
    Posts
    14,987

    Re: Can turn autocalculate back on.

    Maybe a stupid question, but i asked it anyway.

    You active a cell with a formula after running the macro?

    Excel don't actived the recount itself automaticly.

  7. #7
    Forum Expert NBVC's Avatar
    Join Date
    12-06-2006
    Location
    Mississauga, CANADA
    MS-Off Ver
    2003:2010
    Posts
    34,898

    Re: Can turn autocalculate back on.

    Please use code tags, OP... thanks.
    Where there is a will there are many ways.

    If you are happy with the results, please add to the contributor's reputation by clicking the reputation icon (star icon) below left corner

    Please also mark the thread as Solved once it is solved. Check the FAQ's to see how.

  8. #8
    Registered User
    Join Date
    06-27-2012
    Location
    Indianapolis, IN
    MS-Off Ver
    Excel 2010
    Posts
    8

    Re: Can turn autocalculate back on.

    thanks for the reminder
    Last edited by thinlizzy; 06-27-2012 at 04:38 PM.

  9. #9
    Forum Expert NBVC's Avatar
    Join Date
    12-06-2006
    Location
    Mississauga, CANADA
    MS-Off Ver
    2003:2010
    Posts
    34,898

    Re: Can turn autocalculate back on.

    Quote Originally Posted by thinlizzy View Post
    sorry but how?
    use the # icon in the reply or edit box... You can edit your fist post, select the macro and press the # button.

  10. #10
    Registered User
    Join Date
    06-27-2012
    Location
    Indianapolis, IN
    MS-Off Ver
    Excel 2010
    Posts
    8

    Re: Can turn autocalculate back on.

    Let me try to explain better, sorry. What I have is a macro I am using to copy sheets from one location and paste them into the workbook I have open. Then I have the macro rename that runs after that which will fill in some blank cells for me on the sheets I pasted. The problem I have is that I used Application.Calculation = xlCalculationManual
    to speed up the macro. Now when the macro is done none of the formulas I have in other worksheets will update.

  11. #11
    Forum Expert tigeravatar's Avatar
    Join Date
    03-25-2011
    Location
    Colorado, USA
    MS-Off Ver
    Excel 2003 - 2013
    Posts
    5,361

    Re: Can turn autocalculate back on.

    thinlizzy,

    Welcome to the forum!
    Thank you for adding the code tags

    As to your question, your code can be condensed to the following:
    Sub CopyToSheet(ByVal ws As Worksheet)
        
        Dim wb As Workbook
        Dim i As Long
        
        With Application.FileDialog(msoFileDialogFilePicker)
            .Title = "Select " & ws.Name
            .Filters.Clear
            .Filters.Add "Excel Files", "*.xls*"
            If .Show = False Then Exit Sub
            
            Set wb = ActiveWorkbook
            
            With Application
                .Calculation = xlCalculationManual
                .EnableEvents = False
                .DisplayAlerts = False
                .ScreenUpdating = False
            End With
            
            For i = 1 To .SelectedItems.Count
                With Workbooks.Open(.SelectedItems(i))
                    .Sheets(1).UsedRange.Copy ws.Cells(ws.Rows.Count, "A").End(xlUp).Offset(1)
                    .Close False
                End With
            Next i
            
            With Application
                .Calculation = xlCalculationAutomatic
                .EnableEvents = True
                .DisplayAlerts = True
                .ScreenUpdating = True
            End With
            
        End With
        
    End Sub


    Then, to use it you would call it from a main sub, feeding it the destination worksheet, like so:
    Sub Testing()
        
        Dim ws As Worksheet
        
        For Each ws In Sheets(Array("Short Term", "Term", "GSE-TLGP"))
            CopyToSheet ws
        Next ws
        
    End Sub
    Hope that helps,
    ~tigeravatar

    Forum Rules: How to use code tags, mark a thread solved, and keep yourself out of trouble

  12. #12
    Registered User
    Join Date
    06-27-2012
    Location
    Indianapolis, IN
    MS-Off Ver
    Excel 2010
    Posts
    8

    Re: Can't turn autocalculate back on.

    Thanks tigeravatar. I tried what you mentioned, but when each tab is pasted into the workbook it slows down while the formulas are recalculated.

  13. #13
    Forum Expert tigeravatar's Avatar
    Join Date
    03-25-2011
    Location
    Colorado, USA
    MS-Off Ver
    Excel 2003 - 2013
    Posts
    5,361

    Re: Can't turn autocalculate back on.

    You could put the application disable/enable items in the Testing sub instead of the CopyToSheet sub. You will still get a slowdown while the formulas are recalculated, but this way they won't get recalculated until after all sheets have been copied over, instead of being recalculated in between sheet copies per destination sheet.
    Sub CopyToSheet(ByVal ws As Worksheet)
        
        Dim wb As Workbook
        Dim i As Long
        
        With Application.FileDialog(msoFileDialogFilePicker)
            .Title = "Select " & ws.Name
            .Filters.Clear
            .Filters.Add "Excel Files", "*.xls*"
            If .Show = False Then Exit Sub
            
            Set wb = ActiveWorkbook
            
            For i = 1 To .SelectedItems.Count
                With Workbooks.Open(.SelectedItems(i))
                    .Sheets(1).UsedRange.Copy ws.Cells(ws.Rows.Count, "A").End(xlUp).Offset(1)
                    .Close False
                End With
            Next i
            
        End With
        
    End Sub


    Sub Testing()
        
        Dim ws As Worksheet
        
        With Application
            .Calculation = xlCalculationManual
            .EnableEvents = False
            .DisplayAlerts = False
            .ScreenUpdating = False
        End With
        
        For Each ws In Sheets(Array("Short Term", "Term", "GSE-TLGP"))
            CopyToSheet ws
        Next ws
        
        With Application
            .Calculation = xlCalculationAutomatic
            .EnableEvents = True
            .DisplayAlerts = True
            .ScreenUpdating = True
        End With
        
    End Sub

  14. #14
    Registered User
    Join Date
    06-27-2012
    Location
    Indianapolis, IN
    MS-Off Ver
    Excel 2010
    Posts
    8

    Re: Can't turn autocalculate back on.

    that is really good, but is there any way to call out this
    Sub rename()
    Sheets("GSE-TLGP").Activate
        Cells.Replace What:="TLGP *******", Replacement:="TLGP", LookAt:=xlPart, SearchOrder _
        :=xlByRows, MatchCase:=False, SearchFormat:=False, ReplaceFormat:=False
        Cells.Replace What:="Citigroup Inc. (HC)", Replacement:="TLGP", LookAt:=xlPart, SearchOrder _
        :=xlByRows, MatchCase:=False, SearchFormat:=False, ReplaceFormat:=False
        Cells.Replace What:="Sallie Mae", Replacement:="Federal Farm Credit", LookAt:=xlPart, SearchOrder _
        :=xlByRows, MatchCase:=False, SearchFormat:=False, ReplaceFormat:=False
    Sheets("Short Term").Activate
    Dim ce As Range
    Set myRng = ActiveSheet.Range("A15:A250").SpecialCells(xlCellTypeBlanks)
    For Each ce In myRng
        ce.Value = ce.Offset(-1, 0).Value
        If ce.Value = "Total" Then End
        Next ce
    
    End Sub
    so that it will also run in the testing before the calculation gets turned back to automatic?

  15. #15
    Forum Expert tigeravatar's Avatar
    Join Date
    03-25-2011
    Location
    Colorado, USA
    MS-Off Ver
    Excel 2003 - 2013
    Posts
    5,361

    Re: Can't turn autocalculate back on.

    Here's a cleaned up version of the Rename sub:
    Sub Rename()
        
        Dim myRng As Range
        Dim BlankCell As Range
        
        With Sheets("GSE-TLGP").Cells
            .Replace "TLGP *******", "TLGP"
            .Replace "Citigroup Inc. (HC)", "TLGP"
            .Replace "Sallie Mae", "Federal Farm Credit"
        End With
        
        On Error Resume Next
        Set myRng = Sheets("Short Term").Range("A15:A250").SpecialCells(xlCellTypeBlanks)
        On Error GoTo 0
        If myRng Is Nothing Then Exit Sub
        
        For Each BlankCell In myRng
            BlankCell.Value = BlankCell.Offset(-1, 0).Value
            If BlankCell.Value = "Total" Then Exit For
        Next BlankCell
        
    End Sub


    Now, in the Testing sub, put Rename just after the "Next ws" line:
        For Each ws In Sheets(Array("Short Term", "Term", "GSE-TLGP"))
            CopyToSheet ws
        Next ws
        
        Rename
    Last edited by tigeravatar; 06-27-2012 at 05:19 PM.

  16. #16
    Registered User
    Join Date
    06-27-2012
    Location
    Indianapolis, IN
    MS-Off Ver
    Excel 2010
    Posts
    8

    Re: Can't turn autocalculate back on.

    That doesn't help, that solves everything! Thank you so much.

  17. #17
    Forum Expert tigeravatar's Avatar
    Join Date
    03-25-2011
    Location
    Colorado, USA
    MS-Off Ver
    Excel 2003 - 2013
    Posts
    5,361

    Re: Can't turn autocalculate back on.

    You're very welcome

+ 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