[英]VBA to Find And Replace Blank Cells in Excel
有人结束了我的问题,尽管我不知道如何才能更“专注”; 这似乎是一个非常直接和简单的问题:
我正在尝试编写一些 VBA 代码,用另一列中同一行上的值替换工作表一列中的空白单元格。 换句话说,向下移动所有行,如果D列为空,则将其替换为A列。
我试过了,但它只是用 A 列顶行的内容替换了空白值
.Columns("D").Replace What:="", Replacement:=.Columns("A"), LookAt:=xlWhole, SearchOrder:=xlByRows, MatchCase:=False, SearchFormat:=False, ReplaceFormat:=False
有什么建议?
谢谢!
你需要循环这个:
Dim lastRow as Long
lastRow = Range("D" & rows.count).End(xlUp).Row
Dim i as Long
For i = 2 to lastRow ' change 2 if you want to start at any other row
If Cells(i,4).Value = "" Then Cells(i,4).Value = Cells(i,1).Value
Next i
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.