1

我有一个看起来像这样的 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
4

1 回答 1

1

尝试

If Cells(x, 2).Value <> "" and Cells(x, 2).Font.Italic = true then
于 2017-03-20T10:12:19.257 回答