[英]VBA to Find And Replace Blank Cells in Excel
Someone closed my question, although I don't know how it could be more "focused";有人结束了我的问题,尽管我不知道如何才能更“专注”; it seems like a pretty straightforward and simple question:
这似乎是一个非常直接和简单的问题:
I'm trying to write some VBA code to replace blanks cells in one column of a worksheet with the value on the same row in another column.我正在尝试编写一些 VBA 代码,用另一列中同一行上的值替换工作表一列中的空白单元格。 In other words, go down all the rows and if column D is blank, replace it with column A .
换句话说,向下移动所有行,如果D列为空,则将其替换为A列。
I tried this but it just replaces the blank value with the contents of the top row of Column A我试过了,但它只是用 A 列顶行的内容替换了空白值
.Columns("D").Replace What:="", Replacement:=.Columns("A"), LookAt:=xlWhole, SearchOrder:=xlByRows, MatchCase:=False, SearchFormat:=False, ReplaceFormat:=False
Any suggestions?有什么建议?
Thanks!谢谢!
You'd need to loop this:你需要循环这个:
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.