Hello,
I am trying to write a macro and I am having a hard time figuring how to go about it.
The end goal of the macro is to search if there is a value in column D starting at row 20, If TRUE then search for the first "TT" of the row and add a comment (value found in column D).
Then do it for the first TF and FT of the row that same row.
Then go on the next row until it reach row 499.
I am able to find the address of the cell with the specified value.
I am able to create a macro that writes the comment.
what I don't know how to mix them both together properly and apply the loop correctly to go through all the column.
Here a data Sample:
The cells in teal should get a comment. That comment is the value found in the cell on the same row in column D (under the "Dates" cell)
And here is the code I got so far, it gives me an error:
I am trying to write a macro and I am having a hard time figuring how to go about it.
The end goal of the macro is to search if there is a value in column D starting at row 20, If TRUE then search for the first "TT" of the row and add a comment (value found in column D).
Then do it for the first TF and FT of the row that same row.
Then go on the next row until it reach row 499.
I am able to find the address of the cell with the specified value.
I am able to create a macro that writes the comment.
what I don't know how to mix them both together properly and apply the loop correctly to go through all the column.
Here a data Sample:
The cells in teal should get a comment. That comment is the value found in the cell on the same row in column D (under the "Dates" cell)
And here is the code I got so far, it gives me an error:
Code:
Sub Add_Comments()
Dim rng As Range
Dim taskname As Long
'Turns off Conditional formating
Range("D1").Value = "NOCF"
Application.Wait Now + #12:00:02 AM#
For taskname = 20 To 499
'Checks if there is a task on that row
If Not IsEmpty(cell.Offset(taskname, 4).Value) Then
'Start the loop to find and comment cells if value = TT, TF or FT
Set rng = cell.Offset(taskname, 4)
Set taskcmt = Selection.Find(What:="TT", LookIn:=xlValues, LookAt:=xlPart, SearchOrder:=xlByColumns, SearchDirection:=xlNext, MatchCase:=False, SearchFormat:=False)
If Not taskcmt Is Nothing Then
'Add a comment on the current address
Cells(taskname, taskcmt).AddComment rng.Value
End If
'Turns on conditional formating
Else: Range("D1").Value = "CF"
Exit Sub
End If
Next
'Turns on conditional formating
Range("D1").Value = "CF"
End Sub