首页 文章

使用其颜色复制单元格 - Excel

提问于
浏览
0

我有一个数据表如下

COLA        COLB
ABC          10
             10
             15
XYZ          10
             15
             15

我将它从Col A分组的另一个数据块复制到Col B中的多个值 . 现在我使用下面的步骤用上面单元格中的值填充Col A中的所有空白单元格,

选择Col A转到特殊 - >选择空白 - >确定 - >在单元格A3中输入公式为“= A2” - >按Ctrl键 .

这会将上面单元格中的所有值复制到Col A中的所有空白单元格中 .

但是如果突出显示,我希望空白单元格也从父单元格复制颜色 .

我怎样才能在excel中做到这一点?

干杯!!

1 回答

  • 1

    尝试下面的代码

    Sub test()
        lastrow = Range("B" & Rows.Count).End(xlUp).Row
        For i = 2 To lastrow
            If Cells(i, 1) = "" Then
                If Cells(i - 1, 1).Interior.ColorIndex > 0 Then
                    Cells(i, 1) = Cells(i - 1, 1)
                    Cells(i, 1).Interior.Color = Cells(i - 1, 1).Interior.Color
                Else
                    Cells(i, 1) = Cells(i - 1, 1)
                End If
            End If
        Next i
    End Sub
    

相关问题