Hi all!
Stucked with adjusting a code that sums my hours.
I use two codes to get the value of the sum hours. The first one checks if both cBoxes are set, the second one is called after the check for making the sum of the hours.
The looped list is on the second worksheet. The dates I'd like to loop trough is in col B and the hours in D
Code1:
Code 2
My problem is I always get 0 in the tBox. I guess the second code does not work properly.
Can someone help me?
Thank you.
Stucked with adjusting a code that sums my hours.
I use two codes to get the value of the sum hours. The first one checks if both cBoxes are set, the second one is called after the check for making the sum of the hours.
The looped list is on the second worksheet. The dates I'd like to loop trough is in col B and the hours in D
Code1:
VBA Code:
Private Sub ComboBox3_Change()
With Sheets("Entry_form")
If ComboBox2.ListIndex < 0 Or ComboBox3.ListIndex < 0 Then Exit Sub
End With
Call MonthlyHours
End Sub
Code 2
Code:
Private Sub MonthlyHours()
Dim myYear As String
Dim myMonth As String
Dim f As Integer
Dim myList As Range
Dim summonths As Double
myYear = ComboBox2.Value
myMonth = ComboBox3.Value
With Sheets("Data")
Set myList = Sheets("Data").Range("A1:D1").Resize(.Cells(.Rows.Count, 1).End(xlUp).Row)
End With
With myList
For f = 0 To ListCount - 1
If Year(.Cells(f, 2)) = myYear And Month(.Cells(f, 2)) = myMonth Then
summonths = summonths + .Cells(f, 4).Value
End If
Next f
End With
TextBox7.Value = summonths
End Sub
My problem is I always get 0 in the tBox. I guess the second code does not work properly.
Can someone help me?
Thank you.