获取运行时错误1004如何停止错误 [英] Getting runtime error 1004 How to stop error

查看:58
本文介绍了获取运行时错误1004如何停止错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有以下代码,不断出现运行时错误 1004 .您如何或建议如何在 ActiveCell.Offset(1,0)处停止错误.请在以下代码中选择:

I have the following code which I keep getting runtime error 1004. How or what can you suggest to stop error at the ActiveCell.Offset(1, 0).Select in the below code:

Sub RowCounter (count)

Counter = 1
Do Until ActiveCell = ""
Counter = counter + 1
ActiveCell.Offset(1, 0).Select
Loop

Count = Counter > 2000000

推荐答案

该代码计算有多少个具有值的单元格低于活动单元格.尝试执行此操作以避免错误,并在 MsgBox()中显示答案:

The code counts how many cells with value are below the activecell. Try this to avoid the error, showing the answer in a MsgBox():

Sub RowCounter()

    Dim counter As Long
    counter = 1
    Do Until ActiveCell = "" Or ActiveCell.Row <> Rows
        counter = counter + 1
        ActiveCell.Offset(1, 0).Select
    Loop

    MsgBox counter

End Sub

OrActiveCell.Row<>如果 ActiveCell 位于Excel电子表格的最后一行,则确保退出.

The Or ActiveCell.Row <> Rows makes sure to exit, if the ActiveCell is on the last row of the Excel spreadsheet.

关于 .Select ActiveCell 部分,请参阅本主题,并提出一些改进建议:

Concerning the .Select and ActiveCell part, see this topic with some ideas how to improve it:

这篇关于获取运行时错误1004如何停止错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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