将最后一个单元格值复制到单元格组正下方的空白单元格中

时间:2015-12-18 18:30:58

标签: excel excel-vba vba

{{1}}

依此类推,有很多组单元格,但我想在一个空白单元格中复制组单元格的最后一个值。

我还想更改复制的单元格的文本颜色。

请建议我有效的宏。

1 个答案:

答案 0 :(得分:2)

试试这个小宏:

Sub copy_down()
    Dim r As Range, rr As Range, N As Long
    N = Cells(Rows.Count, "A").End(xlUp).Row
    Set r = Range(Cells(1, "A"), Cells(N, "A")).SpecialCells(xlCellTypeBlanks)
    For Each rr In r
        rr.FillDown
    Next
End Sub

修改#1:

要填充一个附加单元格,请使用此版本:

Sub copy_down()
    Dim r As Range, rr As Range, N As Long
    N = Cells(Rows.Count, "A").End(xlUp).Row
    Set r = Range(Cells(1, "A"), Cells(N, "A")).SpecialCells(xlCellTypeBlanks)

    For Each rr In r
        rr.FillDown
    Next

    Cells(N + 1, "A").FillDown
End Sub

<强> BEFORE:

enter image description here

<强> AFTER:

enter image description here