dmars
New Member
- Joined
- Nov 19, 2013
- Messages
- 17
This code works, it moves the comment to the right top corner of the date cell (dc):
Code:
Sub EditMoveComment()
Dim dc As Range
Set dc = ActiveCell
With dc
.Comment.Text Text:="12/14"
.Comment.Shape.Top = .Comment.Parent.Top
.Comment.Shape.Left = .Comment.Parent.Left + 214
End With
End Sub
<code>/[CODE]
</code>
This code doesn't work (problem lines in red font at the end). No compile errors and the debugger steps through them without complaining, but the comment's position doesn't change:
[CODE]Dim down, count, wkdy, date1, tasks As Range, datecell As Range, weekdays() As Variant, _
dates() As Variant
weekdays = Array("Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday", "Sunday")
dates = Array(31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31)
'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 start
For wkdy = 0 To 6
If weekdays(wkdy) = datecell.Value2 Then
GoTo Insert
End If
Next
Insert:
For i = 1 To count
tasks.Copy
ActiveCell.Insert Shift:=xlDown
'put correct weekday in first task
datecell.Value2 = weekdays(wkdy)
'and get it's date
date1 = datecell.Comment.Text
'compose date string
mo = Val(Left(date1, 2))
da = Val(Right(date1, 2))
'test for month change and adjust day
If da + (i - 1) > dates(mo - 1) Then
'need new variable for month, to keep original value in mo
mon = mo + 1
'set day, adjusting for days before eom start day might be
day2 = (i - 1) - dates(mo - 1) - da
'keep month, adjust day
Else
mon = mo
day2 = da + (i - 1)
End If
'edit & move comment
With datecell
.Comment.Text Text:=mon & "/" & day2
[COLOR=#ff0000].Comment.Shape.Top = .Comment.Parent.Top
.Comment.Shape.Left = .Comment.Parent.Left + 214 [/COLOR]
End With
'move ActiveCell to the next day
ActiveCell.Offset(down, 0).Select
Set datecell = ActiveCell.Offset(i * down, 1)
Next
'now fix the last one
<code omitted="">
End Sub
</code><code>/[CODE]</code><code omitted="">
</code>
Last edited: