我有一个宏,它在垂直列中复制了组单元格的最后一个单元格值,例如,
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
编辑(增加了一行),这里是:
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
请在此宏中再添加一项功能。我想更改用红色复制的单元格的文本颜色,类似于添加:
'change formatting to your liking:
formulaCell.Font.Bold = True
formulaCell.Font.Color = RGB(255, 0, 0)
我忘记在之前的上一个问题中问过这个问题。
答案 0 :(得分:2)
如果您只想更改已填充的单元格,请在循环过程中将格式更改添加到 rr 。
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
with rr
.FillDown
.Font.Bold = True
.Font.Color = RGB(255, 0, 0)
end with
Next
End Sub