Excel VBA editing comment if exists

2019-08-30 05:28发布

My code is checking if cell value from 2 sheets are different, if no it continue check for next row, if different it copy from sheet2 to sheet1 the cell value where I need and add to Cell in sheet1(where the value copied too) a comment with the old value. every time when the value changed again it remove the comment and put new one. I need to do a comment check if exist and append the old value to comment. I want that the comment will contain all the old values that changed in the cell.

this is my piece of code:

                        If Not IsEmpty(datasheet.Cells(iData, j).Value) Then
                        comm = user & vbNewLine & "Old Date:" & vbNewLine & ActiveCell.Value
                        datasheet.Cells(iData, j).Copy Destination:=ActiveCell
                        With ActiveCell
                            ActiveCell.Interior.ColorIndex = 0
                            With ActiveCell.Borders
                                .LineStyle = xlContinuous 'Setting style of border line
                                .Weight = xlThin 'Setting weight of border line
                                .ColorIndex = xlAutomatic 'Setting colour of border line
                            End With
                            If Not .Comment Is Nothing Then .Comment.Delete
                                .ClearComments
                                .AddComment
                                .Comment.Text Text:=comm
                                .Comment.Visible = False
                        End With

标签: excel vb.net vba
0条回答
登录 后发表回答