dmars
New Member
- Joined
- Nov 19, 2013
- Messages
- 17
This execution error is one of the strangest ones I've seen in Excel VBA, though admittedly I haven't seen that many.
The "Object required" error occurs at the "Set datecell.Value2 = weekdays(wkdy)" statement. (in red font below)
I've tried several different ways of defining and declaring datecell and weekdays. They all get the "Object required" error on this statement, and looking at the datecell object's properties and the weekdays array, there just doesn't seem to be any good reason to get this error.
Obviously, there is a reason for this error. Whether it's a good one or not remains to be seen, but in any case I'm not seeing what the problem is.
The "Object required" error occurs at the "Set datecell.Value2 = weekdays(wkdy)" statement. (in red font below)
I've tried several different ways of defining and declaring datecell and weekdays. They all get the "Object required" error on this statement, and looking at the datecell object's properties and the weekdays array, there just doesn't seem to be any good reason to get this error.
Code:
Sub InsertNewDays()
Dim down, count, wkdy, tasks As Range, datecell As Range, weekdays() As Variant
'ReDim weekdays(1 To 7)
weekdays = Array("Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday", "Sunday")
'set tasks to columns of tasks to copy
Set tasks = Range(ActiveCell.End(xlDown), ActiveCell.Offset(0, 1))
down = tasks.rows.count
'datecell has the weekday as the task and the comment w/date in it
Set datecell = ActiveCell.Offset(0, 1)
count = InputBox("How many days to insert?", , 2)
'set wkdy pointing to next weekday after given date
For wkdy = 0 To 6
If weekdays(wkdy) = datecell.Value2 Then
wkdy = wkdy + 1
GoTo Insert
End If
Next
Insert:
For i = 1 To count
tasks.Copy
ActiveCell.Insert Shift:=xlDown
'put correct weekday in first task cell
[COLOR=#ff0000]Set datecell.Value2 = weekdays(wkdy)[/COLOR]
unfinished & untested
====================================================
| |
V V
'edit & move comment w/date in it
'datecell.Comment
'if WorksheetFunction.EoMonth(StartDate, 0)
'move ActiveCell to the next day
ActiveCell.Offset(down, 0).Select
'datecell has the weekday as the task and the comment w/date in it
Set datecell = ActiveCell.Offset(i * down, 1)
Next
End Sub
Obviously, there is a reason for this error. Whether it's a good one or not remains to be seen, but in any case I'm not seeing what the problem is.