Comment won't move

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:

Excel Facts

Test for Multiple Conditions in IF?
Use AND(test, test, test, test) or OR(test, test, test, ...) as the logical_test argument of IF.
Found it. When I do the insert-copy of the block datecell is originally assigned to, datecell continues to point to the cell that was copied, which is now the lower block, with the insert-copied block above it. The two move statements (top and left) do execute, moving the original comment to the top right corner of datecell, which is where it was before I copied it, and it doesn't move the new copied comment at all.

The fix was:

For i = 1 To count
tasks.Copy
ActiveCell.Insert Shift:=xlDown

-> 'datecell stays with the original block after the insert-copy,
'need to reset
-> Set datecell = ActiveCell.Offset((i - 1) * down, 1)


This solves the problem and the copied comment is now moved to the top right corner of the new datecell. (Still have to test whether it still works in future iterations of this loop, but it should.)
 
Upvote 0
dmars,

Good that you are sorted.

Re code tags…..

Opening tag requires Code within the square brackets and the closing tag requires /Code within.
 
Upvote 0
Thanks Tony, for the help with the code tags - newbie here... :rolleyes:

I think I've got it now.
 
Upvote 0

Forum statistics

Threads
1,223,236
Messages
6,170,912
Members
452,366
Latest member
TePunaBloke

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top