+ Reply to Thread
Results 1 to 14 of 14

Auto Update vs Button Update

Hybrid View

shymac Auto Update vs Button Update 04-26-2013, 05:07 PM
AndyLitch Re: Auto Update vs Button... 04-26-2013, 05:20 PM
shymac Re: Auto Update vs Button... 04-29-2013, 09:13 AM
AndyLitch Re: Auto Update vs Button... 04-29-2013, 09:36 AM
shymac Re: Auto Update vs Button... 04-29-2013, 10:35 AM
AndyLitch Re: Auto Update vs Button... 04-29-2013, 10:46 AM
shymac Re: Auto Update vs Button... 04-29-2013, 12:53 PM
AndyLitch Re: Auto Update vs Button... 04-29-2013, 12:56 PM
HaHoBe Re: Auto Update vs Button... 04-29-2013, 12:59 PM
shymac Re: Auto Update vs Button... 04-29-2013, 02:39 PM
shymac Re: Auto Update vs Button... 04-29-2013, 04:03 PM
AndyLitch Re: Auto Update vs Button... 04-30-2013, 12:35 AM
arlu1201 Re: Auto Update vs Button... 04-30-2013, 01:19 AM
shymac Re: Auto Update vs Button... 04-30-2013, 10:49 AM
  1. #1
    Registered User
    Join Date
    01-14-2013
    Location
    Ohio
    MS-Off Ver
    Excel 2010
    Posts
    14

    Auto Update vs Button Update

    I have the following code to update a summary page from multiple worksheets, is it possible to have this auto update so that the users don't have to remember to click the button.

    Sub Summary()
        Dim ws As Worksheet
        Dim DestSheet As Worksheet
        Dim j As Long       'row index on destination sheet
        Dim sRow As Long    'row index on source worksheet
        Dim nRow As Long    'last row index on source worksheet
    
        ActiveSheet.Unprotect
    
        Application.ScreenUpdating = False
        Set DestSheet = Worksheets("Summary")
        j = 9
        For Each ws In ActiveWorkbook.Worksheets
            Select Case UCase(ws.Name)
            Case "TEMPLATE", "DROPDOWN"     'Ignore these worksheets (list in all caps!)
            Case Else   'Copy data from all the rest
                nRow = ws.Cells(ws.Rows.Count, "U").End(xlUp).Row
    
                ws.Cells(6, 2).Copy
                DestSheet.Cells(j, 2).PasteSpecial xlPasteValues    'Store Name
                ws.Cells(7, 2).Copy
                DestSheet.Cells(j, 3).PasteSpecial xlPasteValues    'Store Number
                ws.Cells(6, 9).Copy
                DestSheet.Cells(j, 4).PasteSpecial xlPasteValues   'Square Footage
                ws.Cells(13, 16).Copy
                DestSheet.Cells(j, 6).PasteSpecial xlPasteValues     'Professional Fees
                ws.Cells(14, 16).Copy
                DestSheet.Cells(j, 7).PasteSpecial xlPasteValues     'Parts
                ws.Cells(15, 16).Copy
                DestSheet.Cells(j, 8).PasteSpecial xlPasteValues     'Freight
                ws.Cells(16, 16).Copy
                DestSheet.Cells(j, 9).PasteSpecial xlPasteValues     'Contract
                ws.Cells(17, 16).Copy
                DestSheet.Cells(j, 10).PasteSpecial xlPasteValues    'Other Cost
                ws.Cells(18, 16).Copy
                DestSheet.Cells(j, 11).PasteSpecial xlPasteValues    'Contingency
                ws.Cells(22, 5).Copy
                DestSheet.Cells(j, 15).PasteSpecial xlPasteValues    'Base $Variance
                ws.Cells(22, 7).Copy
                DestSheet.Cells(j, 16).PasteSpecial xlPasteValues    'Base SF Variance
                ws.Cells(22, 9).Copy
                DestSheet.Cells(j, 17).PasteSpecial xlPasteValues    'Base %Variance
                ws.Cells(23, 5).Copy
                DestSheet.Cells(j, 18).PasteSpecial xlPasteValues    'SD $Variance
                ws.Cells(23, 7).Copy
                DestSheet.Cells(j, 19).PasteSpecial xlPasteValues    'SD SF Variance
                ws.Cells(23, 9).Copy
                DestSheet.Cells(j, 20).PasteSpecial xlPasteValues    'SD %Variance
                ws.Cells(24, 5).Copy
                DestSheet.Cells(j, 21).PasteSpecial xlPasteValues    'DD $Variance
                ws.Cells(24, 7).Copy
                DestSheet.Cells(j, 22).PasteSpecial xlPasteValues    'DD SF Variance
                ws.Cells(24, 9).Copy
                DestSheet.Cells(j, 23).PasteSpecial xlPasteValues    'DD %Variance
                ws.Cells(25, 5).Copy
                DestSheet.Cells(j, 24).PasteSpecial xlPasteValues    'FC $Variance
                ws.Cells(25, 7).Copy
                DestSheet.Cells(j, 25).PasteSpecial xlPasteValues    'FC SF Variance
                ws.Cells(25, 9).Copy
                DestSheet.Cells(j, 26).PasteSpecial xlPasteValues    'FC %Variance
                ws.Cells(19, 11).Copy
                DestSheet.Cells(j, 27).PasteSpecial xlPasteValues    'Incremental Total
                j = j + 1
    
                If j > 22 Then
                    Rows(j + 1).Insert
                    Rows(j).Copy
                    Rows(j + 1).PasteSpecial Paste:=xlPasteFormats
                End If
    
            End Select
        Next
    
        Range("SumTC").Select
        Selection.Borders(xlDiagonalDown).LineStyle = xlNone
        Selection.Borders(xlDiagonalUp).LineStyle = xlNone
        With Selection.Borders(xlEdgeLeft)
            .LineStyle = xlContinuous
            .Weight = xlThin
        End With
        With Selection.Borders(xlEdgeTop)
            .LineStyle = xlContinuous
            .Weight = xlThin
        End With
        With Selection.Borders(xlEdgeBottom)
            .LineStyle = xlContinuous
            .Weight = xlThin
        End With
        With Selection.Borders(xlEdgeRight)
            .LineStyle = xlContinuous
            .Weight = xlThin
        End With
        With Selection.Borders(xlInsideVertical)
            .LineStyle = xlContinuous
            .Weight = xlThin
        End With
        With Selection.Borders(xlInsideHorizontal)
            .LineStyle = xlContinuous
            .Weight = xlThin
        End With
    
        With Selection.Interior
            .PatternColorIndex = xlAutomatic
            .ThemeColor = xlThemeColorDark1
            .TintAndShade = -4.99893185216834E-02
            .PatternTintAndShade = 0
        End With
    
    
    
    
        Range("SumCtr").Select
        With Selection
            .HorizontalAlignment = xlCenter
            .VerticalAlignment = xlBottom
        End With
    
        Range("SumFeesFmt").Select
        Selection.NumberFormat = "$#,##0_);[Red]($#,##0)"
    
        ActiveSheet.Protect
    
    End Sub
    Last edited by arlu1201; 04-30-2013 at 01:17 AM.

  2. #2
    Valued Forum Contributor
    Join Date
    03-29-2013
    Location
    United Kingdom
    MS-Off Ver
    Office/Excel 2013
    Posts
    1,749

    Re: Auto Update vs Button Update

    You can call your Summary macro from any number of Events ... the question is which event to choose.
    The most commonly used are WorksheetActivate, Auto_Open, SelectionChange

    If you want to update automatically when the workbook opens then try this in a code module

    Sub Auto_open()
         Summary
    End Sub
    Elegant Simplicity............. Not Always

  3. #3
    Registered User
    Join Date
    01-14-2013
    Location
    Ohio
    MS-Off Ver
    Excel 2010
    Posts
    14

    Re: Auto Update vs Button Update

    Hi,

    How would the selection change event work? Ithink if the updates were made as the change occurs or when the workbook is saved would work.

    Thanks

  4. #4
    Valued Forum Contributor
    Join Date
    03-29-2013
    Location
    United Kingdom
    MS-Off Ver
    Office/Excel 2013
    Posts
    1,749

    Re: Auto Update vs Button Update

    Selection_change is triggered when a cell selection is changed.
    Worksheet_Change is triggered when a worksheet value is changed (except by formula)
    Sub Auto_Open is when the workbook is opened Sub Auto_Close when closed
    Workbook_beforesaveas - as part of the save routine.

  5. #5
    Registered User
    Join Date
    01-14-2013
    Location
    Ohio
    MS-Off Ver
    Excel 2010
    Posts
    14

    Re: Auto Update vs Button Update

    I would like to use the Worksheet Change would I go about the same as the code that you provided for Auto_open above?

  6. #6
    Valued Forum Contributor
    Join Date
    03-29-2013
    Location
    United Kingdom
    MS-Off Ver
    Office/Excel 2013
    Posts
    1,749

    Re: Auto Update vs Button Update

    Yes everything Except the Sub/End Sub lines should be inside the Worksheet_Change event

    Got to the worksheet module module
    Select Worksheet in the top left drop down
    Select "Change" in the right hand dropdown

    Put the code above between the sub and end sub of worksheet_change

  7. #7
    Registered User
    Join Date
    01-14-2013
    Location
    Ohio
    MS-Off Ver
    Excel 2010
    Posts
    14

    Re: Auto Update vs Button Update

    Running into a error at the Range("SumTC").Select code

  8. #8
    Valued Forum Contributor
    Join Date
    03-29-2013
    Location
    United Kingdom
    MS-Off Ver
    Office/Excel 2013
    Posts
    1,749

    Re: Auto Update vs Button Update

    That's probably because it's selecting multiple cells which is then triggering the error in the worksheet_change (being multicell)..

    Try putting this in the code

    Private Sub Worksheet_Change(ByVal Target As Range)
        If Target.Rows > 1 Or Target.Columns > 1 Then Exit Sub
    Last edited by AndyLitch; 04-29-2013 at 12:59 PM.

  9. #9
    Forum Guru HaHoBe's Avatar
    Join Date
    02-19-2005
    Location
    Hamburg, Germany
    MS-Off Ver
    work: 2016 on Win10 (notebook), private: 365 on Win11 (desktop), 2019 on Win11 (notebook)
    Posts
    8,198

    Re: Auto Update vs Button Update

    Hi, shymac,

    Your opening post does not comply with Rule 3 of our Forum RULES. Use code tags around code.

    Posting code in [CODE] [/CODE] tags makes your code much easier to read and copy for testing, it also maintains VBA formatting.

    Highlight your code and click the # icon at the top of your post window. More information about these and other tags can be found here

    Ciao,
    Holger
    Use Code-Tags for showing your code: [code] Your Code here [/code]
    Please mark your question Solved if there has been offered a solution that works fine for you

  10. #10
    Registered User
    Join Date
    01-14-2013
    Location
    Ohio
    MS-Off Ver
    Excel 2010
    Posts
    14

    Re: Auto Update vs Button Update

    Hi,

    Added:
    Private Sub Worksheet_Change(ByVal Target As Range)
    If Target.Rows > 1 Or Target.Columns > 1 Then Exit Sub

    And it error at the same line? Adding workbook added to the last two worksheets before the Summary tab.
    Attached Files Attached Files
    Last edited by shymac; 04-29-2013 at 02:47 PM.

  11. #11
    Registered User
    Join Date
    01-14-2013
    Location
    Ohio
    MS-Off Ver
    Excel 2010
    Posts
    14

    Re: Auto Update vs Button Update

    So I updated the code and excluded everything related to formatting in the change event and changed to selectionchange. Is there anyway to improve performance there is a 5-10 sec delay when a field is selected?

  12. #12
    Valued Forum Contributor
    Join Date
    03-29-2013
    Location
    United Kingdom
    MS-Off Ver
    Office/Excel 2013
    Posts
    1,749

    Re: Auto Update vs Button Update

    Try this
    Private Sub Worksheet_SelectionChange(ByVal Target As Range)
    Application.screenupdating = false
    Application.calculation = xlmanual
         ' Main body of code
    Application.screenupdating = true
    Application.calculation = xlautomatic
    End Sub

  13. #13
    Forum Contributor arlu1201's Avatar
    Join Date
    09-09-2011
    Location
    Bangalore, India
    MS-Off Ver
    Excel 2003 & 2007
    Posts
    19,167

    Re: Auto Update vs Button Update

    shymac,

    You were asked to put code tags in post 9.

    I have added code tags to your 1st post. As per forum rule 3, you need to use them whenever you put any code in your post. Please add them in future. In order to put code tags, either type [CODE] before your code and [/CODE] at the end of it, OR you can highlight your code and click the # icon at the top of your post window.
    If I have helped, Don't forget to add to my reputation (click on the star below the post)
    Don't forget to mark threads as "Solved" (Thread Tools->Mark thread as Solved)
    Use code tags when posting your VBA code: [code] Your code here [/code]

  14. #14
    Registered User
    Join Date
    01-14-2013
    Location
    Ohio
    MS-Off Ver
    Excel 2010
    Posts
    14

    Re: Auto Update vs Button Update

    Added to the existing selectionchnge code the screenupdate = false was already there, but the Application.screenupdating = true line caused a longer delay as it toggled the summary and template worksheets back and forth as it ran through the code. Added each line and it didn't make a difference in the performance the lag was still there on each click to a new cell.

+ 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