Monday, June 13, 2011

Use of one cell value as a comment in another

    Sub Add_Comments()
        strSheet1Name = "Sheet1"
        strSheet2Name = "Sheet2"
        strSheet2Col = "F"
        strSheet1Col = "P"
        ActiveWorkbook.Sheets(strSheet2Name).Activate
        For intRow = 2 To ActiveSheet.Range(strSheet2Col & "65536").End(xlUp).Row
        If ActiveSheet.Range(strSheet2Col & intRow).Comment Is Nothing Then
            If ActiveWorkbook.Sheets(strSheet1Name).Range(strSheet1Col & intRow).Value <> "" Then
            ActiveSheet.Range(strSheet2Col & intRow).AddComment ActiveWorkbook.Sheets(strSheet1Name).Range(strSheet1Col & intRow).Value
            End If
        Else
            ActiveSheet.Range(strSheet2Col & intRow).Comment.Delete
            If ActiveWorkbook.Sheets(strSheet1Name).Range(strSheet1Col & intRow).Value <> "" Then
            ActiveSheet.Range(strSheet2Col & intRow).AddComment ActiveWorkbook.Sheets(strSheet1Name).Range(strSheet1Col & intRow).Value
            End If
        End If
        Next
        MsgBox "Done"
    End Sub

No comments:

Post a Comment