Может быть, что-то вроде этого.
Следует зациклить все строки и найти дубликаты в столбце «А».Если найден дубликат, а в строке с дублированием нет комментариев, копируется последний известный комментарий.
Если дубликат найден, но уже есть комментарий, этот комментарий становится новым «последним известным» для дальнейших дубликатов.
Option Explicit
Sub Dupes()
Dim Ws As Worksheet
Dim LastRow As Long, i As Long, j As Long, DupCounter As Long, DupPos As Long
Dim MatNo As String, Comment As String
Dim Found As Boolean
Dim ArrDuplicates() As Variant 'Declare dynamic array
Set Ws = ThisWorkbook.Sheets(1)
'Redimennsion/change size of declared array
ReDim ArrDuplicates(1 To 2, 1 To 1)
DupCounter = 1
With Ws
'find last row with data in column "A"
LastRow = .Cells(.Rows.Count, 1).End(xlUp).Row
'Loop all rows from 1 to last
For i = 1 To LastRow
'reset variables for each loop
Found = False
DupPos = 0
MatNo = .Cells(i, 1)
Comment = .Cells(i, 3) 'Column 3 is column "C" if other
'column to be used just change the number
'Search array with previous data and look for duplicates
For j = LBound(ArrDuplicates(), 2) To UBound(ArrDuplicates(), 2)
'If material number currently checked found in array
If MatNo = ArrDuplicates(1, j) Then
'If comment for current row is empty, take comment from array
If Trim(Comment) = "" Then
Comment = ArrDuplicates(2, j)
End If
'remember position of source data in array (first occurence
'of material number)
DupPos = j
'set "Found" marker
Found = True
'leave loop
Exit For
End If
Next j
'if no duplicate found
If Not Found Then
'redimension array. "Preserve" keyword added to keep values
'already existing in array
ReDim Preserve ArrDuplicates(1 To 2, 1 To DupCounter)
'insert new data to array ((first occurance of material number)
ArrDuplicates(1, DupCounter) = MatNo
ArrDuplicates(2, DupCounter) = Comment
DupCounter = DupCounter + 1 'increase counter used to redimension array
Else 'if material number found in array
'if commnet variable is same as comment in array
'This means that comment of current row was empty
If Comment = ArrDuplicates(2, DupPos) Then
.Cells(i, 3) = Comment 'put comment in current row and column 3 "C"
Else
'Commnet in current row was not empty and different than last one
'replace "last known comment" in array for material number
'with new one from current row
ArrDuplicates(2, DupPos) = Comment
End If
'change font colour
.Cells(i, 3).Font.Color = vbRed
End If
Next i
End With
End Sub
Редактировать: Добавлено несколько комментариев
Проверить также ReDim Statement