【问题标题】:Excel VBA: Copy and paste duplicate values based on font formatExcel VBA:根据字体格式复制和粘贴重复值
【发布时间】:2017-08-11 13:12:52
【问题描述】:

我的 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

【问题讨论】:

  • 需要告诉你,StackOverflow 不是免费的代码编写服务。到目前为止你尝试了什么?你能告诉我们你的代码吗?
  • 嗨,@Peh。这就是我到目前为止所拥有的: Sub FillDuplicates() Dim lastrow As Long lastrow = Cells(Rows.Count, "A").End(xlUp).Row 'find A 列中的最后一行 For x = 1 To lastrow If Cells (x, 2).Value "" Then '检查 B 列中的单元格是否为空 For y = 1 To lastrow If Cells(y, 1).Value = Cells(x, 1).Value Then '比较单元格与A列中的每个值 Cells(y, 2).Value = Cells(x, 2).Value '如果匹配,则在B列中添加值 End If Next y End If Next x End Sub
  • 我只是想知道是否有办法识别文本是否为斜体?
  • 下次请不要使用 cmets 添加代码。您可以编辑问题以添加代码或图像等内容。
  • 好的。很抱歉给您带来不便。

标签: vba excel duplicates italic


【解决方案1】:

试试

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-01-22
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-12-16
    相关资源
    最近更新 更多