I am attempting to create an annual calendar that will automatically determine is year of calendar is a Leap Year. I can do this using a formula in a cell then assigning the value of that cell to the variable. Is is possible to assign the iDays value without first writing the formula to the worksheet then assigning the value of the cell with the formula to the iDays variable.
Dim iYear As Integer, iDays As Integer
Dim strPrompt As String, strTitle As String
strPrompt = "Enter Year of Calendar"
strTitle = "YEAR"
iYear = InputBox(strPrompt, strTitle) 'Year of the calendar to be created.
ActiveSheet.Range("AK1").Value = iYear
'Formula to determine if the year is a Leap year
ActiveSheet.Range("Z1").Formula = "=IF(OR(MOD(AK1,400)=0,AND(MOD(AK1,4)=0,MOD(AK1,100)<>0)),29, 28)"
iDays = ActiveSheet.Range("Z1").Value 'Value of iDays used to cut the month of February at 28 or 29.
MsgBox "There are " & iDays & " days in the month of February " & iYear & "."
I've done this before with VLookup using WorksheetFunction with the following code:
lStart = Application.WorksheetFunction.VLookup(dStart2, rng, 3, False)