JohnDoe2022
New Member
- Joined
- Jul 9, 2023
- Messages
- 4
- Office Version
- 365
- Platform
- Windows
- MacOS
Hello,
I am having trouble with constructing an If statement between dates. I want the template to place a note if column "A"(Date of Birth) has #N/A or if the termination date is less than the end of the current month to place a note in column E that says "Termed" and if column "A"(Date of Birth) is over age 21 to place a note in column "E" to say "Over 21". I want the macros to run thru all cells till empty because each time the report is run, there will be a different number of lines. I have reference cells for the End of Current month and the date that will be over 21. Each month the report is run, those dates will change. I am not very familiar with VBA, and it is probably really easy, but I am having a hard time.
This is what I have so far; I know I am probably completely off.
Sub Over21()
Dim sDate As Long
Dim Eom As Long
Eom = Range("H2").Value
sDate = Range("I2").Value
For i = 2 To 1500
If Worksheets("Sheet1").Cells(i, 1).Value = "#N/A" Then
Worksheets("Sheet1").Cells(i, 5).Value = "Termed"
ElseIf Worksheets("Sheet1").Cells(i, 3).Value <= Eom Then
Worksheets("Sheet1").Cells(i, 5).Value = "Termed"
ElseIf Worksheets("Sheet1").Cells(i, 1).Value <= sDate Then
Worksheets("Sheets1").Cells(i, 5).Value = "Over 21"
End If
Next
End Sub
Any help is very much appreciated!!
I am having trouble with constructing an If statement between dates. I want the template to place a note if column "A"(Date of Birth) has #N/A or if the termination date is less than the end of the current month to place a note in column E that says "Termed" and if column "A"(Date of Birth) is over age 21 to place a note in column "E" to say "Over 21". I want the macros to run thru all cells till empty because each time the report is run, there will be a different number of lines. I have reference cells for the End of Current month and the date that will be over 21. Each month the report is run, those dates will change. I am not very familiar with VBA, and it is probably really easy, but I am having a hard time.
This is what I have so far; I know I am probably completely off.
Sub Over21()
Dim sDate As Long
Dim Eom As Long
Eom = Range("H2").Value
sDate = Range("I2").Value
For i = 2 To 1500
If Worksheets("Sheet1").Cells(i, 1).Value = "#N/A" Then
Worksheets("Sheet1").Cells(i, 5).Value = "Termed"
ElseIf Worksheets("Sheet1").Cells(i, 3).Value <= Eom Then
Worksheets("Sheet1").Cells(i, 5).Value = "Termed"
ElseIf Worksheets("Sheet1").Cells(i, 1).Value <= sDate Then
Worksheets("Sheets1").Cells(i, 5).Value = "Over 21"
End If
Next
End Sub
Any help is very much appreciated!!