Hello,
I have found myself in a confusing syntax situation. The code included shows how i desire to use the application.workbookfunction.date().
It produces different errors as i tinker with it leading me to ask for insight from someone more knowledgeable then myself. (I having only a few days experience with VBA)
This code produces this error at "cdate1="
run-time error '438':
Object doesnt support this property or method.
Suggestions?
Thanks in advance for your help and im sorry if this topic was answered before. (i couldnt find a solution)
I have found myself in a confusing syntax situation. The code included shows how i desire to use the application.workbookfunction.date().
It produces different errors as i tinker with it leading me to ask for insight from someone more knowledgeable then myself. (I having only a few days experience with VBA)
This code produces this error at "cdate1="
run-time error '438':
Object doesnt support this property or method.
Suggestions?
Thanks in advance for your help and im sorry if this topic was answered before. (i couldnt find a solution)
Code:
Private Sub UserForm_Initialize()
Dim cmonth As Range
Dim cday As Range
Dim ws As Worksheet
Set ws = ThisWorkbook.Sheets("Sheet2")
For Each cmonth In ws.Range("Month")
With Me.month1
.AddItem cmonth.Value
End With
Next cmonth
For Each cday In ws.Range("Day")
With Me.day1
.AddItem cday.Value
End With
Next cday
For Each cmonth In ws.Range("Month")
With Me.month2
.AddItem cmonth.Value
End With
Next cmonth
For Each cday In ws.Range("Day")
With Me.day2
.AddItem cday.Value
End With
Next cday
Me.month1 = "January"
Me.day1 = 1
Me.year1 = 2000
Me.month2 = "January"
Me.day2 = 2
Me.year2 = 2000
End Sub
Private Sub compute_Click()
'Dim cdate1 As Double
'Dim cdate2 As Double
'Dim cans As Double
[COLOR="Red"]cdate1 = Application.workbookfunction.Date(Me.year1, Me.month1, Me.day1)
cdate2 = Application.workbookfunction.Date(Me.year2, Me.month2, Me.day2)[/COLOR]
If Me.weekend.Value = False Then
cans = cdate2 - cdate1
Else: Me.weekend.Value = True
ans = workbookfunction.NetworkDays(cdate1, cdate2)
Me.result.Value = cans
End If
End Sub