Hi all!
I have a issue with my register.
I have data in a 4 column listbox. In the fourth I have hours and in the third I have the worktype (can be two types). I'd like to have the sum hours of the two types and show them in two textboxes.
I tried to filter the listbox and sum the selected data but in this case the listbox content always changed and I don't want that.
So I moved to a differnt method.
I have a code that filters the data on a sheet where the listbox gets the data. I also have a function in a standard module that sums the visible cells. I'd like to call the function in the filter code but can't refer properly.
Can someone help?
Or if someone can offer me an easier solution that's ok too.
Thanks.
Filter code:
Sum code:
I have a issue with my register.
I have data in a 4 column listbox. In the fourth I have hours and in the third I have the worktype (can be two types). I'd like to have the sum hours of the two types and show them in two textboxes.
I tried to filter the listbox and sum the selected data but in this case the listbox content always changed and I don't want that.
So I moved to a differnt method.
I have a code that filters the data on a sheet where the listbox gets the data. I also have a function in a standard module that sums the visible cells. I'd like to call the function in the filter code but can't refer properly.
Can someone help?
Or if someone can offer me an easier solution that's ok too.
Thanks.
Filter code:
VBA Code:
Dim Code As String
Dim myDB As Range
If TextBox1.Value < 0 Then Exit Sub
Code = TextBox1.Value
With Sheets("Data")
Set myDB = Sheets("Data").Range("A1:D1").Resize(.Cells(.Rows.Count, 1).End(xlUp).Row)
End With
With myDB
.AutoFilter 'remove filters
.AutoFilter field:=1, Criteria1:=Code 'filter data
.AutoFilter field:=3, Criteria1:="Design"
Call SumVisible(???????) 'here I always get the ByRef argument error
.AutoFilter
End With
Sum code:
VBA Code:
Function SumVisible(WorkRng As Range) As Double
Dim rng As Range
Dim total As Double
For Each rng In WorkRng
If rng.Rows.Hidden = False And rng.Columns.Hidden = False Then
total = total + rng.Value
End If
Next
TextBox2.Value = total
End Function