将值向下填充到列中的空白单元格
以下示例查看 A 列,如果有空白单元格,则将空白单元格的值设置为等于其上方单元格的值。 此过程将继续沿整个列向下,将值向下填充到每个空白单元格中。
示例代码提供者:Tom Urtis,Atlas Programming Management
Sub FillCellsFromAbove()
' Turn off screen updating to improve performance
Application.ScreenUpdating = False
On Error Resume Next
' Look in column A
With Columns(1)
' For blank cells, set them to equal the cell above
.SpecialCells(xlCellTypeBlanks).Formula = "=R[-1]C"
'Convert the formula to a value
.Value = .Value
End With
Err.Clear
Application.ScreenUpdating = True
End Sub
关于参与者
MVP Tom Urtis 是 Atlas Programming Management 的创始人,这是一家位于硅谷的全服务型 Microsoft Office 和 Excel 业务解决方案公司。 Tom 在业务管理和 Microsoft Office 应用程序开发方面拥有 25 年以上的经验,与他人合著过“Holy Macro! It's 2,500 Excel VBA Examples”(Holy Macro! 2,500 个 Excel VBA 示例)。
支持和反馈
有关于 Office VBA 或本文档的疑问或反馈? 请参阅 Office VBA 支持和反馈,获取有关如何接收支持和提供反馈的指南。
反馈
https://aka.ms/ContentUserFeedback。
即将发布:在整个 2024 年,我们将逐步淘汰作为内容反馈机制的“GitHub 问题”,并将其取代为新的反馈系统。 有关详细信息,请参阅:提交和查看相关反馈