excel - 检查重复项时出现 VBA 运行时错误 1004“应用程序定义或对象定义错误”
问题描述
我遇到了错误 1004“应用程序定义或对象定义错误”的问题。
我以前多次使用完全相同的代码,但由于某种原因,我无法让它在这个 sub 中起作用。
Sub Checkduplicates()
Dim tracker As Workbook
Set tracker = ActiveWorkbook
With tracker.Sheets("Tracker")
Dim sEntity As String, sAmt As Double, sRow As Integer
sEntity = .Cells(Row, 6).Value
sAmt = .Cells(Row, 11).Value
If Row > 1010 Then sRow = Row - 1000 Else sRow = 4
For sRow = sRow To Row - 1
If .Cells(sRow, 6).Value = sEntity And .Cells(sRow, 11).Value = sAmt Then
Call GetAnswer
End If
Next sRow
End With
End Sub
解决方案
row
in sEntity = .Cells(row, 6).Value
andsAmt = .Cells(row, 11).Value
是未声明和未定义的。看起来它应该是 F 列中最后一个填充的单元格。
Sub Checkduplicates()
Dim tracker As Workbook
Set tracker = ActiveWorkbook
With tracker.Sheets("Tracker")
Dim sEntity As String, sAmt As Double, sRow As LONG, rw as LONG
rw = .cells(.rows.count, "F").end(xlup).row
sEntity = .Cells(rw, 6).Value
sAmt = .Cells(rw, 11).Value
If Row > 1010 Then sRow = Row - 1000 Else sRow = 4
For sRow = sRow To rw - 1
If .Cells(sRow, 6).Value = sEntity And .Cells(sRow, 11).Value = sAmt Then
Call GetAnswer
End If
Next sRow
End With
End Sub
使用选项显式。
推荐阅读
- c# - '进程无法访问文件'logs\dashboard.log',因为它正被另一个进程使用。' 在多任务环境中
- pyspark - 使用 pyspark 开发火花流但未获得预期结果
- apache-camel - 以编程方式获取 Apache Camel 组件操作、参数、选项说明
- php - PHP 如果状态为 OR 未按预期运行
- bitbucket - 如何使用 REST API 获取用户对 bitbucket 存储库的访问级别?
- c# - MVC - 缓存控制不适用于静态内容
- c# - 如何确保 API 一次只处理一个请求
- elasticsearch - 弹性搜索,过滤器无法使用 java.sql.Time 对象
- swift - 快速比较元组时难以理解
- sql-server - 如何使用带有游标的 sql 来创建 SSIS 包?