vba - 复制时 VBA 应用程序定义或对象定义错误
问题描述
我正在编写一个代码,它将数据从另一个工作簿复制到当前打开的工作簿。但是,我遇到了我一直在思考但无法找到原因的应用程序定义或对象定义错误。这就是为什么我决定在这里发布我的问题并希望得到一些帮助。请在下面找到我的代码:
Option Explicit
Sub copyDataSEA()
Application.DisplayAlerts = False
Application.ScreenUpdating = False
Dim destWs As Worksheet
Set destWs = ThisWorkbook.Worksheets("Sheet1")
Dim Report As Workbook
Set Report = Workbooks.Open(Filename:="C:\Users\John\Documents\My Docs\Report 2020 EMEA_SEA_SA Region.xlsx")
Dim sourceWs As Worksheet
Set sourceWs = Report.Worksheets("Raw")
Dim lastRow As Long
lastRow = sourceWs.Range("A" & sourceWs.Rows.CountLarge).End(xlUp).Row
Dim outRow As Long
outRow = 2
'Copying Header of source
destWs.Rows(1).EntireRow.Value = sourceWs.Rows(1).EntireRow.Value
Dim i As Long
For i = 2 To lastRow
If sourceWs.Cells(i, 6) = "INDONESIA" Or sourceWs.Cells(i, 6) = "MALAYSIA" Or sourceWs.Cells(i, 6) = "THAILAND" Or sourceWs.Cells(i, 6) = "VIETNAM" _
Or sourceWs.Cells(i, 6) = "CAMBODIA" Or sourceWs.Cells(i, 6) = "MYANMAR" Or sourceWs.Cells(i, 6) = "PHILIPPINES" Or sourceWs.Cells(i, 6) = "SINGAPORE" Then
destWs.Rows(outRow).EntireRow.Value = sourceWs.Rows(i).EntireRow.Value
outRow = outRow + 1
End If
Next i
Report.Close False
Application.DisplayAlerts = True
Application.ScreenUpdating = True
End Sub
我在这一行遇到错误
destWs.Rows(outRow).EntireRow.Value = sourceWs.Rows(i).EntireRow.Value
遇到错误时,outRow 的值为 25728,而 i 为 44246。源文档的列数为 74518。
解决方案
推荐阅读
- php - 如何使用 React 从数据库中删除数据,并点击我使用 php 和 mysql 创建的 rest API?
- serial-port - 不同传输介质的最大消息长度
- regex - Reg Ex 从“#9NE832”中删除“#”
- python-3.x - 我无法通过 kivy 获得两次交易之间的时差
- python - 我的代码正在生成一条即使满足所有条件也不应该生成的消息。怎么了?
- php - 如何在 Laravel 中使用 WHERE 子句和 WITH
- angular - tslint 在最新的 Angular 版本中不起作用
- node.js - 如何为电子安装 node-hid
- python - 测试准确度好,但混淆矩阵结果差
- javascript - Vue.js- Vuex 更新数组中的对象,内部状态未反映在组件 DOM 中