I have an excel spreadsheet that has one column with dates (written "mmddyyyy") and a Function that checks dates to see whether they are Monday-Friday, or Saturday-Sunday:
Public Function IsWeekend(InputDate As Date) As Boolean
Select Case Weekday(InputDate)
Case vbSaturday,vbSunday
IsWeekend = True
Case vbMonday, vbTuesday, vbWednesday, vbThursday, vb Friday
IsWeekend = False
End Select
End Function
I have another sub that I am trying to write that checks the IsWeekend returned values and assigns "Yes" or "No" values to column based on whether or not the date entered is a weekend. So far, this is what I have:
Sub weekcheck()
Dim X As Range
For i = 3 To 1500
**If Worksheets("Sheet1").Cells(i,3).Value <> 0 Then**
Set X = Worksheets("Sheet1").Cells(i,3).Value
If X = True Then
Worksheets("Sheet1").Cells(i,3).Value = "Yes"
ElseIf X = False Then
Worksheets("Sheet1").Cells(i,3).Value = "No"
End If
End If
Next i
End Sub
Whenever this sub is called by another sub (Worksheet_Change), it generates and error message: "Application-defined or Object-defined error" and highlights the line that I have added "**" to. I am trying to figure out how to correct this and get it to be able to run without errors, but in addition was wondering if there was any possible way of creating a third option within the Public Function? I realize that - as it is currently a Boolean argument - that only leaves the option of True or False, but is there a way to create a "True", "False", and "Other" option for the Public Function, to then work with the Sub weekcheck (if there is a way to get Sub weekcheck() to behave...)?
Any help is greatly appreciated.
Thanks
Aucun commentaire:
Enregistrer un commentaire