2015-12-18 125 views
-2
Column A 
2 
5 
7 
(It is blank cell, but I want to copy 7 that is last value of this group cell) 
5 
1 
2 
5 
(It is blank cell, but I want to copy 5 that is last value of this group cell) 
2 
5 
(It is blank cell, but I want to copy 5 that is last value of this group cell) 

等等,有很多组单元格,但我想将组单元格的最后一个值复制到空白单元格中。复制单元格组下方的空白单元格中的最后一个单元格的值

我也想改变被复制的单元格的文本颜色。

请建议我有效的宏。

+1

的可能重复http://stackoverflow.com/questions/33656858/scroll-through-column-from-top-to-底部和替换0s-with-value-from-cell-ab/33656961#33656961 –

+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 

前:

enter image description here

AFTER:

enter image description here

+0

谢谢。我该如何改变那个单元格的颜色。例如。 '更改格式以符合您的喜好: formulaCell.Font.Bold = True formulaCell.Font.Color = RGB(255,0,0) –

+0

我也成功实现了更改文本颜色。但是我在这个宏中发现了一个问题,它不会复制列的最后一个组单元格值。我可以手动完成,但如果你可以完成这个宏,那么它是非常好的解决方案。请帮忙。 –

+0

@RanjeetRai看我的**编辑#1 ** –

相关问题