用上面的值填充任何空单元格 [英] Filling any empty cells with the value above
本文介绍了用上面的值填充任何空单元格的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想使用上述单元格的值填充所有空单元格
I want to fill in all empty cells using values of above cells
state name
IL Mike
Sam
CA Kate
Bill
Leah
应该是如下
state name
IL Mike
IL Sam
CA Kate
CA Bill
CA Leah
我尝试了以下
Sub split()
Dim columnValues As Range, i As Long
Set columnValues = Selection.Area
Set i = 1
For i = 1 To columnValues.Rows.Count
If (columnValues(i) = "") Then
columnValues(i) = columnValues(i - 1)
End If
Next
End Sub
当我设置 i
时,我收到错误。如何修改我的代码
I get an error when I set i
. How can I modify my code
推荐答案
这是因为我
应该是定义为 i = 1
。尽管代码中还有一些其他问题。我会把它改为这样的:
It is because i
should be defined as i=1
. There are although a few other problems with the code. I would change it to something like this:
Sub split()
Dim columnValues As Range, i As Long
Set columnValues = Selection
i = 1
For i = 1 To columnValues.Rows.Count
If columnValues.Cells(i, 1).Value = "" Then
columnValues.Cells(i, 1).Value = columnValues.Cells(i - 1, 1).Value
End If
Next
End Sub
这篇关于用上面的值填充任何空单元格的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文