Welcome . I have this code to bring the values of column E to F. Numbering duplicate values in parentheses works well. I want to add a condition to fetch data provided that there is a value in column M, or ignore the numbering of duplicate values when checking that there is no corresponding value in column M.
VBA Code:
Sub test()
Dim r As Range: Set r = ActiveSheet.Range("E7:E" & Range("E" & Rows.Count).End(xlUp).Row)
Dim AR() As Variant: AR = r.Value2
Dim Res() As Variant: ReDim Res(1 To UBound(AR), 1 To 1)
With CreateObject("Scripting.Dictionary")
For i = 1 To UBound(AR)
If Not .Exists(AR(i, 1)) Then
.Add AR(i, 1), 1
Res(i, 1) = AR(i, 1)
Else
.Item(AR(i, 1)) = .Item(AR(i, 1)) + 1
Res(i, 1) = AR(i, 1) & " (" & .Item(AR(i, 1)) & ")"
End If
Next i
r.Offset(, 1).Value2 = Res
End With
End Sub