Porschemaniac
Technical User
Hi there,
OK, I'm a bit new to VBA - and new to this forum - so please be gentle!!!
Currently, I am building an Excel spreadsheet to manage training records.
At the moment, I am trying to put together a routine, which interrogates a list of 'Date of completion' dates (relating to the dates various courses were completed) and then returns a simple count of how many courses have been completed during the last 30 days.
The dates are stored in a sheet called 'Providers Mapping' and I am running the count routine from a sheet, called 'Stats', using a command button.
I have put together the following for this:
Private Sub CommandButton1_Click()
Dim Cell As Range
Dim CurDate As Date
Dim ctr As Integer
Dim ctra As Integer
Dim CellDate As Date
Dim Cellct As Integer
CurDate = Date
For Each Cell In Worksheets("Providers Mapping").Range("I3:I394")
Cellct = Cellct + 1
CellDate = ActiveCell.Value
Debug.Print "Active Cell Value " & CellDate & "Todays Date is " & CurDate
If CurDate - CellDate <= 30 Then
ctr = ctr + 1
End If
If CurDate - CellDate >= 30 Then
ctra = ctra + 1
End If
Next Cell
Worksheets("Stats").Range("B6") = "Courses Marked Complete during the last 30 days " & ctr
Worksheets("Stats").Range("B7") = "Courses Marked Complete More than 30 days ago " & ctra
Worksheets("Stats").Range("B11") = "Cells Checked " & Cellct
Worksheets("Stats").Range("B14") = "Todays Date is " & CurDate
End Sub
The problem is that the count of courses completed during the last 30 days is always 0.
As you can see, I have added a Debug.Print function and this confirms that the dates being returned from the 'Providers Mapping' sheet are all coming back as 00:00:00.
The dates in the 'Providers Mapping' sheet are all cortrectly formatted as dates, so I really am at a loss as to explain what is going on.
Any help that anyone can offer me on this will be greatly appreciated.
Thanks,
Ian.
OK, I'm a bit new to VBA - and new to this forum - so please be gentle!!!
Currently, I am building an Excel spreadsheet to manage training records.
At the moment, I am trying to put together a routine, which interrogates a list of 'Date of completion' dates (relating to the dates various courses were completed) and then returns a simple count of how many courses have been completed during the last 30 days.
The dates are stored in a sheet called 'Providers Mapping' and I am running the count routine from a sheet, called 'Stats', using a command button.
I have put together the following for this:
Private Sub CommandButton1_Click()
Dim Cell As Range
Dim CurDate As Date
Dim ctr As Integer
Dim ctra As Integer
Dim CellDate As Date
Dim Cellct As Integer
CurDate = Date
For Each Cell In Worksheets("Providers Mapping").Range("I3:I394")
Cellct = Cellct + 1
CellDate = ActiveCell.Value
Debug.Print "Active Cell Value " & CellDate & "Todays Date is " & CurDate
If CurDate - CellDate <= 30 Then
ctr = ctr + 1
End If
If CurDate - CellDate >= 30 Then
ctra = ctra + 1
End If
Next Cell
Worksheets("Stats").Range("B6") = "Courses Marked Complete during the last 30 days " & ctr
Worksheets("Stats").Range("B7") = "Courses Marked Complete More than 30 days ago " & ctra
Worksheets("Stats").Range("B11") = "Cells Checked " & Cellct
Worksheets("Stats").Range("B14") = "Todays Date is " & CurDate
End Sub
The problem is that the count of courses completed during the last 30 days is always 0.
As you can see, I have added a Debug.Print function and this confirms that the dates being returned from the 'Providers Mapping' sheet are all coming back as 00:00:00.
The dates in the 'Providers Mapping' sheet are all cortrectly formatted as dates, so I really am at a loss as to explain what is going on.
Any help that anyone can offer me on this will be greatly appreciated.
Thanks,
Ian.