View Single Post
 
Old 04-03-2018, 08:24 AM
Divinedar Divinedar is offline Windows 7 64bit Office 2010 64bit
Novice
 
Join Date: Jun 2016
Posts: 21
Divinedar is on a distinguished road
Default Variable for Date not working

I have the following codes

HTML Code:
Function PrjByMonth(strField As String, pMonth As Date)
 
Dim sht As Worksheet, i As Long, j As Integer

PrjByMonth = 0
 
 
For Each sht In ActiveWorkbook.Sheets
    If Mid(sht.Name, 1, 2) = "FY" Then
        For j = 3 To 14 'The row of dates. Starts at C1 to N1
        
            If sht.Cells(1, j) = pMonth Then
                For i = 2 To 30 'update with max row
                    If sht.Cells(i, 2) = strField Then
                        PrjByMonth = PrjByMonth + CDbl(sht.Cells(i, j))
                        GoTo nxtSht
                    End If
                Next i
            End If
        Next j
    End If
 
nxtSht: Next
 
End Function

Public Sub ViewPrjByMth()
Dim strField As String, pMonth As Date
Worksheets("PrjByMth").Visible = True
Sheets("PrjByMth").Activate
PrjByMonth strField, pMonth
End Sub
I attached a picture of the results that I'm getting that I just can't figure out why this line "If sht.Cells(1, j) = pMonth Then" is not giving me the correct information. Please help.
Attached Images
File Type: png Temp.png (179.8 KB, 31 views)
Reply With Quote