PDA

View Full Version : count days



enfantter
01-09-2010, 08:35 AM
Hi all,

i have written the following code for a function that is supposed to count all saturdays for example

Function betsum(rg, navn)
Dim tilsum As Double
Dim nRow As Range
For Each nRow In rg
If nRow.Cells(1, 1).Value = navn Then
tilsum = tilsum + 1
End If
Next nRow
betsum = tilsum
End Function


in the column though is dateentries ..
so im looking for a way to alter the code for something like the following,
If dayof(nRow.Cells(1, 1).Value) = navn Then
tilsum = tilsum + 1
End If

is this possible ?!

enfantter
01-09-2010, 08:55 AM
ok i was actually too quick to post this one solution enclosed below
Function betsum(rg, navn)
Dim tilsum As Double
Dim nRow As Range
For Each nRow In rg
If Weekday(nRow.Cells(1, 1).Value) = navn Then
tilsum = tilsum + 1
End If
Next nRow
betsum = tilsum
End Function

xld
01-09-2010, 12:54 PM
How about just

=SUMPRODUCT(--(rng<>""),--(WEEKDAY(rng)=7))