user3445540
user3445540

Reputation: 21

Excel VBA: Copy and paste duplicate values based on font format

I have an Excel format that looks like this:

enter image description here

What I need is a VBA code in Excel that will read all the data in column A and look for any text in italic format then check if it has a duplicate data on the same column. If yes, that data will be written on column B.

This is what I have so far:

 Sub FillDuplicates()
    Dim lastrow As Long
    lastrow = Cells(Rows.Count, "A").End(xlUp).Row 'find last row in column A

    For x = 1 To lastrow
        If Cells(x, 2).Value <> "" Then 'Check if cell in column B is empty
            For y = 1 To lastrow
                If Cells(y, 1).Value = Cells(x, 1).Value Then 'Compares cell against each value in column A
                    Cells(y, 2).Value = Cells(x, 2).Value 'If matches, add value in column B
                End If
            Next y
        End If
    Next x
 End Sub

Upvotes: 1

Views: 108

Answers (1)

Pspl
Pspl

Reputation: 1474

Try

If Cells(x, 2).Value <> "" and Cells(x, 2).Font.Italic = true then

Upvotes: 1

Related Questions