Lew*_*lop 5 debugging excel vba excel-vba
在我的宏中,我有一个查看范围的段,找到并填充空白单元格.
Range("E10:A" & CStr(bottom - 1)).Select
Selection.SpecialCells(xlCellTypeBlanks).Select
Selection.Value = "N/A"
Run Code Online (Sandbox Code Playgroud)
哪里
bottom = ActiveSheet.Cells(Rows.Count, "B").End(xlUp).Row
Run Code Online (Sandbox Code Playgroud)
当空白单元格存在于该范围内时,这非常有效,但会抛出"1004错误:未找到单元格".在specialcells.select行.我无法想出一个简单的方法来解决这个问题.
我知道我可以在范围内运行循环来首先检查空白单元格,但我觉得这种方法会很慢而且很笨重.
有没有人有更快和/或更简单的解决方案?
PS我知道我可以巩固我上面的代码行,我在这里简单地将它放在这里以便更容易理解;
Range("E10:A" & CStr(bottom - 1)).SpecialCells(xlCellTypeBlanks).Value = "N/A"
Run Code Online (Sandbox Code Playgroud)
小智 13
你可以做些什么来避免错误弹出是添加一个错误处理程序
例如:
Sub Main()
On Error GoTo NoBlanks
Range("A1:A10").SpecialCells(xlCellTypeBlanks).Value = "N/A"
NoBlanks:
Resume Next
' or add code here to execute when there are no empty cells
End Sub
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
44116 次 |
最近记录: |