kyddrivers
Board Regular
- Joined
- Mar 22, 2013
- Messages
- 59
- Office Version
- 365
- Platform
- Windows
I have a file with 500+ rows of data. I would like to write a script that will loop thru and do 1 calculation (ABC) if month(C2)-Month(D2) = 0 or do a different calculation (XYZ) if month(C2)-Month(D2) <> 0
Columns C & D are formatted as Date
Each time I run the code, I get a Type 13 Mismatch at the calc variable. I have tried setting Calc as Long, getting the same error.
How do I assign the result of month(C2)-Month(D2) to the Calc variable so I can proceed from there?
Thanks!
Columns C & D are formatted as Date
ID | Week | Week Start | Week End | |
---|---|---|---|---|
3 | 1 | 1/1/2023 | 1/7/2023 | ABC |
3 | 5 | 1/29/2023 | 2/4/2023 | XYZ |
VBA Code:
Sub Calc_Test ()
Dim Calc as Integer
Calc = Application.Evaluate("Month(R2C3)-Month(R2C4)")
' rest of the script goes here
End Sub
Each time I run the code, I get a Type 13 Mismatch at the calc variable. I have tried setting Calc as Long, getting the same error.
How do I assign the result of month(C2)-Month(D2) to the Calc variable so I can proceed from there?
Thanks!