Results 1 to 1 of 1

Any way to have values on a separate tab recalculate?

Threaded View

  1. #1
    Registered User
    Join Date
    12-17-2009
    Location
    rochester, ny
    MS-Off Ver
    Excel 2010
    Posts
    39

    Any way to have values on a separate tab recalculate?

    I have a workbook in which staff members input their days worked on one tab. On a separate tab, they choose expense categories from drop-down menus that automatically calculate expenses.

    It works fine if they input their hours first and then pick the expense category. However, if they then go back and change their hours worked, the expenses on the other tab do not recalculate unless they reselect the expenses.

    Is there any way to add a line to the code so it recalculates when changes are made on the hours worked tab?

    Attached is an example workbook. You can see how initially the 10 days worked for employee A results in $390 printing expenses on the other tab. But, if you then change it to 5 days worked, the printing expenses remain $390 unless you relesect "Printing" from the drop-down menu.

    Below is the code on the expense page.

    Thanks in advance.

    Private Sub Worksheet_Change(ByVal Target As Range)
    
        Dim a As Double, b As Integer, c As Range, d As Integer, e As Integer
        
        ActiveSheet.Unprotect
        Application.EnableEvents = False
    
        ' The Target is the particular cell result you are checking and unless the active cell is
        ' one of those defined the macro does not execute
    
        If Not Intersect(Target, Range("e5,i5,l5,e28,i28")) Is Nothing Then
    
            ' This part clears complete range before writing new, or when the target cell is cleared.
    
            Range(Target.Offset(1, 0), Target.Offset(16, 1)).ClearContents
            Range(Target.Offset(1, 0), Target.Offset(16, 1)).Locked = False
            ' Here the Match function is used to lookup the values associated with the drop down list
            ' it checks the range for applicable values and copies them to the target range.
    
            If Target.Value <> "" Then
            
            Let a = Application.Match(Target.Value, Range("Source"), 0)
            
            For e = 23 To 52 Step 3
            If Cells(a, e).Value <> "" Then Let b = b + 1 ' allows for up to 10 items
            Next e
            
                If b > 0 Then
                    For d = 1 To b
                    Let Target.Offset(d, 0).Value = Cells(a, 20 + d * 3).Value
                    Let Target.Offset(d, 0).Locked = True
                    Let Target.Offset(d, 1).Value = Cells(a, 20 + d * 3 + 1).Value
                    If Cells(a, 20 + d * 3 + 2).Value = "x" Then
                    Let Target.Offset(d, 1).Locked = False
                    Else
                    Let Target.Offset(d, 1).Locked = True
                    End If
                    Next d
                End If
    
            End If
    
        End If
        
        ActiveSheet.Protect
        Application.EnableEvents = True
    
    End Sub
    Attached Files Attached Files

Thread Information

Users Browsing this Thread

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

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