Excel VBA:复制和粘贴基于字体格式的重复值

我有一个Excel格式,看起来像这样:

在这里输入图像说明

我需要的是Excel中的VBA代码,它将读取列A中的所有数据,并以斜体格式查找任何文本,然后检查它是否在同一列上有重复的数据。 如果是,那么这些数据将被写在B列上。

这是我迄今为止:

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 

尝试

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