I'm trying to set up a system such that if a start and end date falls between two separate weeks, I want to find the last day of the week first week (friday in this case) and then input to a cell so that the first date to the last day of the week are in the same row and create a next cell that will go from the ldotw to either the next ldotw or the end date.
My code so far is:
With Sheets(p)
If WorksheetFunction.WeekNum(startdate, 15) <> _ WorksheetFunction.WeekNum(enddate, 15) Then
ldotw = UserForm1.startdate.Value - _
Weekday(UserForm1.startdate.Value, vbFriday) + 7
While Not equal
.Cells(oneRow, 6) = WorksheetFunction.WeekNum(startdate, 15)
.Cells(oneRow, 7) = UserForm1.startdate.Text
.Cells(oneRow, 9) = ldotw
'makes sure to get the last week of values
If WorksheetFunction.WeekNum(startdate, 15) = _ WorksheetFunction.WeekNum(enddate, 15) Then
equal = True
End If
'sets up variables for the next week
oneRow = oneRow + 1
UserForm1.startdate.Text = ldotw
ldotw = ldotw + 7
If WorksheetFunction.WeekNum(startdate, 15) = WorksheetFunction.WeekNum(enddate, 15) Then
ldotw = UserForm1.enddate.Value
End If
Wend
ElseIf WorksheetFunction.WeekNum(startdate, 15) = _ WorksheetFunction.WeekNum(enddate, 15) Then
.Cells(oneRow, 7) = UserForm1.startdate.Text
.Cells(oneRow, 9) = ldotw
hours = .Cells(oneRow, 9) - .Cells(oneRow, 7)
End If
End With
An error occurs on ldotw = UserForm1.startdate.Value - Weekday(UserForm1.startdate.Value, vbFriday) + 7
.