Insert Comments that has Changed Only(This is a tough one)

centaur63

New Member
Joined
Aug 31, 2006
Messages
42
Ok what i need to do with this code now is make it so that it only inserts the comment that has changed since the last time i ran it. Right now it keeps inserting the same cells over and over again. Can You please help me with this one!!!!



Code:
Private Sub PrintCommentsByColumn()
  
  Dim cell As Range
  Dim myrange As Range, myrangeC As Range
  Dim col As Long
  Dim RowOS As Long
  Dim wsSource As Worksheet
  Dim wsNew As Worksheet
  If ActiveSheet.Comments.Count = 0 Then
    MsgBox "No comments in entire sheet"
    Exit Sub
  End If
  Application.ScreenUpdating = False
  Application.Calculation = xlCalculationManual
  Set wsSource = ActiveSheet
  Sheets.Add
  Set wsNew = ActiveSheet
  wsSource.Activate
  With wsNew.Columns("A:D")
      .VerticalAlignment = xlTop
      .WrapText = True
  End With
  wsNew.Columns("B").ColumnWidth = 15
  wsNew.Columns("C").ColumnWidth = 15
  wsNew.Columns("D").ColumnWidth = 60
  wsNew.PageSetup.PrintGridlines = True
  RowOS = 2
  wsNew.Cells(1, 4) = "'" & Application.ActiveWorkbook.FullName & " -- " & _
      Application.ActiveSheet.Name
  For col = 1 To ActiveSheet.UsedRange.Columns.Count
     Set myrangeC = Intersect(ActiveSheet.UsedRange, Columns(col), _
         Cells.SpecialCells(xlCellTypeComments))
     If myrangeC Is Nothing Then GoTo nxtCol
     For Each cell In myrangeC
        If Trim(cell.Comment.Text) <> "" Then
           RowOS = RowOS + 1
           wsNew.Cells(RowOS, 1) = "'" & cell.Address(0, 0) & ":"
           wsNew.Cells(RowOS, 2) = "'" & Date & "     " & Time
           wsNew.Cells(RowOS, 3) = "'" & cell.Text
           wsNew.Cells(RowOS, 4) = "'" & cell.Comment.Text
        End If
     Next cell
nxtCol:
  Next col
  wsNew.Activate
  Application.Calculation = xlCalculationAutomatic
  Application.ScreenUpdating = True
End Sub
 

Excel Facts

VLOOKUP to Left?
Use =VLOOKUP(A2,CHOOSE({1,2},$Z$1:$Z$99,$Y$1:$Y$99),2,False) to lookup Y values to left of Z values.
Hi,

2 questions
this sounds like you are continuing a thread: do you have good reasons to start a new one ?
if so:
how do you define
comment that has changed since the last time i ran it

kind regards,
Erik
 
Upvote 0
Excel

Yeah, My Original question was answer from the last post. I needed to know how to get it to run again. Because each time i ran it it would overwrite the previous entries. You guys helped me get that part working. Now i need to eliminate all the extra parts i just want the comments that has changed inserted. I belived it to be a different question. If this is a problem that i started a new thred i will gladly go back to the otherone.
 
Upvote 0
it's up to you to decide to start a new thread :-)
it's the task of the admins to judge about it
I was only asking it to help you, since the guys who originally helped you would know more about it ...

still need an answer
how do you define
comment that has changed since the last time i ran it
probably a little sample will help
 
Upvote 0
Thanks

I appreciate you trying to help me. Do you have any clue how i can get this code to work??? Ive been trying to figure this out for a while now.
 
Upvote 0
Re: Thanks

I appreciate you trying to help me. Do you have any clue how i can get this code to work??? Ive been trying to figure this out for a while now.
I really want to help but already asked more info twice: try answering the question: it might be a wrong question, but then explain what you are trying to do !

let's put it another way
your code is creating an extra sheet
  A   B                     C           D                                      
1                                       C:\WINDOWS\Desktop\Book1.xls -- Sheet1 
2                                                                              
3 A2: 11/09/06     20:54:35 contents A2 just some text in A2 comment           
4 A5: 11/09/06     20:54:35 typed in A5 just some text in A5 comment           

sheet2

[Table-It] version 06 by Erik Van Geit
what would you like to happen when running the code again ?

please be explicit using the example
if the example is not OK, then provide another one please

best regards,
Erik
 
Upvote 0
I edited the code for better reading and maintenance
it does NOT do anything else then the one you posted, it's just a question of layout-functionality
Code:
Option Explicit

Private Sub PrintCommentsByColumn()
  
Dim wsSource As Worksheet
Dim wsNew As Worksheet
Dim cell As Range
Dim myUsedRange As Range
Dim myrangeC As Range
Dim col As Long
Dim RowOS As Long


    If ActiveSheet.Comments.Count = 0 Then
    MsgBox "No comments in active sheet", 48, "END CODE"
    Exit Sub
    End If
    
Application.ScreenUpdating = False
Application.Calculation = xlCalculationManual

Set wsSource = ActiveSheet
Set myUsedRange = wsSource.UsedRange

Sheets.Add
Set wsNew = ActiveSheet


    With wsNew
        With .Columns("A:D")
        .VerticalAlignment = xlTop
        .WrapText = True
        End With
    .Columns("B").ColumnWidth = 15
    .Columns("C").ColumnWidth = 15
    .Columns("D").ColumnWidth = 60
    .PageSetup.PrintGridlines = True
    .Cells(1, 4) = ActiveWorkbook.FullName & " -- " & wsSource.Name
    
        RowOS = 2

        For col = 1 To myUsedRange.Columns.Count
        Set myrangeC = Intersect(myUsedRange, wsSource.Columns(col), wsSource.Cells.SpecialCells(xlCellTypeComments))
            If Not myrangeC Is Nothing Then
                For Each cell In myrangeC
                    If Trim(cell.Comment.Text) <> "" Then
                    RowOS = RowOS + 1
                    .Cells(RowOS, 1) = "'" & cell.Address(0, 0) & ":"
                    .Cells(RowOS, 2) = "'" & Date & "     " & Time
                    .Cells(RowOS, 3) = "'" & cell.Text
                    .Cells(RowOS, 4) = "'" & cell.Comment.Text
                    End If
                Next cell
            End If
        Next col

    End With

wsNew.Activate

Application.Calculation = xlCalculationAutomatic
Application.ScreenUpdating = True

End Sub
 
Upvote 0
Sorry

Ok, I just changed it where it points to a sheet called test. So what it does is insert all comment from the first worksheet into this worksheet called test. Then once the program runs again it then inserts this information again without overwriting the prevous entry. What I want it to do now is Only insert the comments that has changed sense the last time the program was ran. The code i just submitted is the updated one.

This is what I want to happen: When Code is ran the first time:

A B C D
Cell Changed date Changed Value Comment
j20 9/11/06 5 I was 6
j34 9/11/06 7 i was 22
j55 9/11/06 8 I was 9

Once this is inserted And i Run it again i only want the cells that changed to be inserted again like this:

A B C D
Cell Changed date Changed Value Comment
j20 9/11/06 5 I was 6
j20 9/11/06 8 I was 5
j34 9/11/06 7 i was 22
j55 9/11/06 8 I was 9


Code:
Sub PrintCommentsByColumn() 
  
  Dim cell As Range 
  Dim myrange As Range, myrangeC As Range 
  Dim col As Long 
  Dim RowOS As Long 
  Dim wsSource As Worksheet 
  Dim wsNew As Worksheet 
  If ActiveSheet.Comments.Count = 0 Then 
    MsgBox "No comments in entire sheet" 
    Exit Sub 
  End If 
  Application.ScreenUpdating = False 
  Application.Calculation = xlCalculationManual 
  Set wsSource = ActiveSheet 
  Set wsNew = Sheets("Test") 
  wsSource.Activate 
  With wsNew.Columns("A:D") 
      .VerticalAlignment = xlTop 
      .WrapText = True 
  End With 
  wsNew.Columns("B").ColumnWidth = 15 
  wsNew.Columns("C").ColumnWidth = 15 
  wsNew.Columns("D").ColumnWidth = 60 
  wsNew.PageSetup.PrintGridlines = True 
  RowOS = wsNew.Range("A65536").End(xlUp).Row 
  wsNew.Cells(1, 4) = "'" & Application.ActiveWorkbook.FullName & " -- " & _ 
      Application.ActiveSheet.Name 
  For col = 1 To ActiveSheet.UsedRange.Columns.Count 
     Set myrangeC = Intersect(ActiveSheet.UsedRange, Columns(col), _ 
         Cells.SpecialCells(xlCellTypeComments)) 
     If myrangeC Is Nothing Then GoTo nxtCol 
     For Each cell In myrangeC 
        If Trim(cell.Comment.Text) <> "" Then 
           RowOS = RowOS + 1 
           wsNew.Cells(RowOS, 1) = "'" & cell.Address(0, 0) & ":" 
           wsNew.Cells(RowOS, 2) = "'" & Date & "     " & Time 
           wsNew.Cells(RowOS, 3) = "'" & cell.Text 
           wsNew.Cells(RowOS, 4) = "'" & cell.Comment.Text 
        End If 
     Next cell 
nxtCol: 
  Next col 
  wsNew.Activate 
  Application.Calculation = xlCalculationAutomatic 
  Application.ScreenUpdating = True 
End Sub


Does this make sense?? If not i can explain more. Sorry again for not being more detailed. I thank you for your patience
 
Upvote 0
OK,
I see now
we will put all cells at the end if the address is not found in the list
if the address is found and the comment has not changed it will be skipped
a sort at the end will put the lines together

would you mind having only the celladdresses without the ":" (don't see why you would need that)
it would enhance the process
 
Upvote 0

Forum statistics

Threads
1,223,231
Messages
6,170,884
Members
452,364
Latest member
springate

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