Hey all! I am trying to check a range of cells in col a to see if they fall within this year and if so, add the value of a column/cell, say "I" in the same row to "b". Here is the code I'm trying to use.
VBA Code:
Private Sub Worksheet_Activate()
Dim a As Integer
Dim b As Integer
Dim StartDate As Long
Dim EndDate As Long
Dim totl As Long
Dim rng As Range
Dim daterng As Range
StartDate = "1/1/2021"
EndDate = "12/31/2021"
a = 0
b = 0
Set daterng = Range("A2:A366")
Set rng = Range("I2:I366")
For Each cell In rng
If daterng >= StartDate And daterng <= EndDate Then
If cell > -15 Then
b = cell.Value + 15
totl = totl + b
Else
End If
End If
Next cell
Range("J9").Value = totl
End Sub