用字符串值替换空白/空单元格 [英] Replace Blank/empty cell with a string value
问题描述
希望有人能帮忙.我需要在具有特定字符串的单元格范围内填充任何空白/空单元格.我也不知道最后一行会在那个范围内,所以我首先要寻找它,我知道这行代码有效,因为我已将它用于脚本中的另一个函数.以下是我正在使用的代码:-
Hope someone can help. I need to populate any blank/empty cells within a range of cells with a specific string. I also don't know that the last row would be in that range so I am looking for that first, I know that line of code works as I have used it for another function within the script. Below is the code I am using: -
LastRow = Cells(Rows.Count, 2).End(xlUp).Row
For Each r In Range("AS22:AU" & LastRow)
If r.Value2 = vbNullString Then
r.Value2 = "Greens"
End If
Next
我在运行代码时似乎没有遇到任何编译错误,它只是不起作用,我仍然有相同的空白/空单元格.
I don't seem to get any compile errors when I run the code, it just does not work, I still have the same blank/empty cells.
谁能解释一下我做错了什么?
Can anyone shed any light onto what I am doing wrong?
推荐答案
您可以使用 .Replace
方法 与范围.会快很多.
You could just use the .Replace
Method with the range. It would be much quicker.
Range("AS22:AU" & LastRow).Replace "", "Greens", xlWhole
这篇关于用字符串值替换空白/空单元格的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!