我有一张表格,有时G列(第7列)中缺少数据。
到目前为止,我使用鼠标在此列中选择了一个范围,然后运行此宏以使用“无数据”填充空单元格:
Sub FillEmptyCell()
Dim cell As Range
Dim InputValue As String
For Each cell In Selection
If IsEmpty(cell) Then
cell.Value = "No Data"
End If
Next
End Sub
然而,该列中的数据不断增加,我希望自动选择第7列的整个表格范围,使用“无数据”填充空单元格。
如何实施?
答案 0 :(得分:0)
试试这个
Dim lr As Long
lr = Cells(Rows.Count, 7).End(xlUp).Row
Dim Rng As Range
Set Rng = Range("G1:G" & lr)
For Each cell In Rng
If IsEmpty(cell) Then
cell.Value = "No Data"
End If
Next