1004错误:没有发现细胞,容易解决? [英] 1004 Error: No cells were found, easy solution?

查看:181
本文介绍了1004错误:没有发现细胞,容易解决?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的宏中,我有一个段来查看范围,找到并填充空白单元格。

In my macro, I have a segment which looks at a range, and finds and fills the blank cells.

Range("E10:A" & CStr(bottom - 1)).Select
Selection.SpecialCells(xlCellTypeBlanks).Select
Selection.Value = "N/A"

其中

bottom = ActiveSheet.Cells(Rows.Count, "B").End(xlUp).Row

当范围内存在一个空白单元格但是抛出1004错误:没有找到单元格在specialcells.select行。想到一个简单的方法来解决这个问题,我有麻烦。

This works perfectly when a blank cell is present within the range, but throws "1004 Error: No cells were found." at the specialcells.select line. I am having trouble of thinking of an easy way to fix this problem.

我知道我可以运行一个循环遍历范围来首先检查空白单元格,但我觉得这种方法会慢而笨。

I understand that I could run a loop through the range to first check for blank cells, but I feel that this method would be slow and clunky.

有没有人有更快和/或更简单的解决方案?

Does anyone have a quicker and/or easier solution?

PS我知道我可以巩固我的上述代码行,我刚刚把这个放在这里,以便更容易理解;

PS I know that I can consolidate my above lines of code, I just laid it out like this here to be easier to understand;

    Range("E10:A" & CStr(bottom - 1)).SpecialCells(xlCellTypeBlanks).Value = "N/A"


推荐答案

你可以做什么来避免错误弹出添加错误处理程序

What you could do to avoid the error popping up is add an error handler

例如:

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

这篇关于1004错误:没有发现细胞,容易解决?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆