Consulting

Results 1 to 3 of 3

Thread: comment autosize help

  1. #1
    VBAX Tutor
    Joined
    Jan 2008
    Posts
    266
    Location

    comment autosize help

    how can i merge these two loops in to one?

    [VBA]
    For k = i To i + j - 1
    For l = i To i + j - 1
    If k <> l Then
    Range("G" & k).comment.Text Text:=Range("G" & k).comment.Text & _
    Chr(10) & Range("E" & l).Value & _
    " " & Range("L" & l).Value
    End If
    Next l
    Next k
    i = i + j - 1

    Set myRng = Range("G6", "G" & n1) 'sets the range in myRng

    Application.StatusBar = "Adjusting the size of the comments"
    'below it sets the size on each comment to autosize
    For Each mycell In myRng.Cells
    If Not (mycell.comment Is Nothing) Then
    With mycell.comment
    .Shape.TextFrame.AutoSize = True
    End With
    End If
    Next mycell[/VBA]

    in the upper loop i tried: Range("G" & k).Comment.Shape.TextFrame.AutoSize = True
    but it doesnt work.

    it feels so stupid to have a code that first creates the comment then leaves it, and a few seconds later it has to find the comment again and adjust the size of the comment.

  2. #2
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    This seems to work fine for me

    [vba]

    For k = i To i + j - 1
    For l = i To i + j - 1
    If k <> l Then
    With Range("G" & k).Comment
    .Text Text:=Range("G" & k).Comment.Text & _
    Chr(10) & Range("E" & l).Value & _
    " " & Range("L" & l).Value
    .Shape.TextFrame.AutoSize = True
    End With
    End If
    Next l
    Next k
    [/vba]
    ____________________________________________
    Nihil simul inventum est et perfectum

    Abusus non tollit usum

    Last night I dreamed of a small consolation enjoyed only by the blind: Nobody knows the trouble I've not seen!
    James Thurber

  3. #3
    VBAX Tutor
    Joined
    Jan 2008
    Posts
    266
    Location
    offcourse!
    thanks alot!

    the strange thing is that the code is much slower now than it was before the change.

    first i noticed that it autosized every time it made a new entry in the comment so i moved the with-autosize part to between next l and next k.

    but it still was about one minute slower.
    strange.

    without the change it takes about 10 seconds to do the whole script, after 1 minute +

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •