用于填充选定内容中的空白区域的宏。它不喜欢我的 rng 变量,即使使用 Set 和范围声明也是如此。
Sub fill2()
Dim Rng As Range
Set Rng = Application.InputBox("Range here", Type:=8)
ActiveCell.Range("Rng").Select
Selection.SpecialCells(xlCellTypeBlanks).Select
Application.CutCopyMode = False
Selection.FormulaR1C1 = "=+R[-1]C"
End Sub
您可以使用 Excel 本机功能或 VBA 执行此操作
正如您要求VBA一样。
VBA代码:
Sub fill2()
Dim evalRange As Range
Set evalRange = Application.InputBox("Range here", Type:=8)
On Error Resume Next
evalRange.SpecialCells(xlCellTypeBlanks).FormulaR1C1 = "=R[-1]C"
On Error GoTo 0
End Sub
Excel 本机功能:
- 选择范围
- 按:F5键
- 点击:特殊
- 选择:空白
- 类型:
=
- 用鼠标选择上面的单元格 按
- :按 Ctrl + 输入