+ Reply to Thread
Results 1 to 7 of 7

Comment shall display Cell values of another worksheet

Hybrid View

  1. #1
    Registered User
    Join Date
    04-26-2011
    Location
    NY
    MS-Off Ver
    Excel 2003
    Posts
    3

    Comment shall display Cell values of another worksheet

    Hi all,

    I am basicly looking for a way to display reasons for a delay that are stored in Sheet1 and Sheet2 (Columns H and I) in worksheet3, when someone moves over or clicks on the delay time in worksheet3 (E8, E9,...) .

    Meaning that every comment is different.

    Having googelt and browsed here, I found out that this might be done via macro and comment.

    Can someone help me with this as I have no idea how to program it.

    Attached I have inserted a rough draft of my excel document, also having visualized what I`d like to see.
    If you have any questions, just write them down here. I will answer asap.

    Thanks and best regards
    Attached Files Attached Files

  2. #2
    Forum Expert tigeravatar's Avatar
    Join Date
    03-25-2011
    Location
    Colorado, USA
    MS-Off Ver
    Excel 2003 - 2013
    Posts
    5,361

    Re: Comment shall display Cell values of another worksheet

    dasbroth,

    The following macro will update comments as desired (based on the example workbook you provided). To make it work in the real one, update the sheetnames in the code. The columns for rngArr and rngDep (currently E and L) may also need to be adjusted if they are not in the same columns as the example workbook. This macro runs when a button is clicked that then updates all the comments. The button only needs to be clicked if a comment needs to be updated or added. I've attached a modified version of your example workbook so you can see how it works.

    Sub UpdateComments()
    
        Dim wsArr As Worksheet: Set wsArr = Sheets("Sheet1")
        Dim wsDep As Worksheet: Set wsDep = Sheets("Sheet2")
        
        Dim rngArr As Range:    Set rngArr = ActiveSheet.Range("E8:" & Cells(Rows.Count, 5).End(xlUp).Address)
        Dim rngDep As Range:    Set rngDep = ActiveSheet.Range("L8:" & Cells(Rows.Count, 12).End(xlUp).Address)
        Dim ArrCell As Range, DepCell As Range, strComment As String, cIndex As Long
        
        cIndex = 1
        For Each ArrCell In rngArr
            cIndex = cIndex + 1
            strComment = wsArr.Range("H" & cIndex).Value & " - " & wsArr.Range("I" & cIndex).Value
            On Error Resume Next
            ArrCell.Comment.Delete
            ArrCell.AddComment Text:=strComment
            ArrCell.Comment.Shape.TextFrame.AutoSize = True
        Next ArrCell
        
        cIndex = 1
        For Each DepCell In rngDep
            cIndex = cIndex + 1
            strComment = wsDep.Range("H" & cIndex).Value & " - " & wsDep.Range("I" & cIndex).Value
            On Error Resume Next
            DepCell.Comment.Delete
            DepCell.AddComment Text:=strComment
            DepCell.Comment.Shape.TextFrame.AutoSize = True
        Next DepCell
        
    End Sub


    Hope that helps,
    ~tigeravatar
    Attached Files Attached Files

  3. #3
    Registered User
    Join Date
    04-26-2011
    Location
    NY
    MS-Off Ver
    Excel 2003
    Posts
    3

    Re: Comment shall display Cell values of another worksheet

    Wow, thank you very much!!!!
    This is really great!!!

    Can you tell me, how the macro needs to be changed in order to display the comments not only in one line, but also in two lines?

    Again, thank you!

    Sebastian

  4. #4
    Forum Expert tigeravatar's Avatar
    Join Date
    03-25-2011
    Location
    Colorado, USA
    MS-Off Ver
    Excel 2003 - 2013
    Posts
    5,361

    Re: Comment shall display Cell values of another worksheet

    Sebastian,

    I'm not entirely sure what you mean. Isn't the macro already putting comments down two columns? Or are you looking for something else?

    ~tigeravatar

  5. #5
    Registered User
    Join Date
    04-26-2011
    Location
    NY
    MS-Off Ver
    Excel 2003
    Posts
    3

    Re: Comment shall display Cell values of another worksheet

    Yeah, you are right.

    Maybe I did explain it bad today.

    What I would like to have is that the comment box is displayed in two rows, like in the attached image.

    the Macro pulls all the information in one line.

    Thanks and regards,
    Sebastian
    Attached Files Attached Files
    Last edited by dasbroth; 04-27-2011 at 11:46 AM.

  6. #6
    Forum Expert snb's Avatar
    Join Date
    05-09-2010
    Location
    VBA
    MS-Off Ver
    Redhat
    Posts
    5,649

    Re: Comment shall display Cell values of another worksheet

    or:
    Sub snb()
      sq = Sheets("sheet1").Cells(1, 8).CurrentRegion
      sn = Sheets("sheet2").Cells(1, 8).CurrentRegion
        
      For Each cl In Sheets("sheet3").Columns(5).SpecialCells(2, 1)
        cl.Comment.Text sq(cl.Row - 6, 1) & "-" & vbLf & sq(cl.Row - 6, 2)
      Next
        
      For Each cl In Sheets("sheet3").Columns(12).SpecialCells(2, 1)
        cl.Comment.Text sn(cl.Row - 6, 1) & "-" & vbLF & sn(cl.Row - 6, 2)
      Next
    End Sub
    Last edited by snb; 04-27-2011 at 12:17 PM.



+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

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

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1