excel VBA中出现运行时错误"1004“:应用程序定义或对象定义错误,怎么解决
资产表通过3、4、5列与设备表匹配PrivateSubCommandButton1_Click()Dimarr,brr,crrDimd,strDimi,mSetSh1=S...
资产表通过3、4、5列与设备表匹配
Private Sub CommandButton1_Click()
Dim arr, brr, crr
Dim d, str
Dim i, m
Set Sh1 = Sheets("资产表")
Set Sh2 = Sheets("设备表")
Set Sh3 = Sheets("结果")
Set d = CreateObject("scripting.dictionary")
With Sh1
arr = .Range("a2:e" & .Cells(.Rows.Count, 1).End(3).Row)
End With
With Sh2
brr = .Range("a2:e" & .Cells(.Rows.Count, 1).End(3).Row)
End With
ReDim crr(1 To 10000, 1 To 5)
For i = 1 To UBound(arr)
str = arr(i, 3) & "/" & arr(i, 4) & "/" & arr(i, 5)
If Not d.exists(str) Then
m = m + 1
d(str) = m
crr(m, 1) = arr(i, 1)
crr(m, 3) = arr(i, 3)
crr(m, 4) = arr(i, 4)
crr(m, 5) = arr(i, 5)
Else
crr(d(str), 1) = crr(d(str), 1) & "/" & arr(i, 1)
End If
Next
For i = 1 To UBound(brr)
str = brr(i, 3) & "/" & brr(i, 4) & "/" & brr(i, 5)
If d.exists(str) Then
If crr(d(str), 2) <> "" Then
crr(d(str), 2) = crr(d(str), 2) & "/" & brr(i, 1)
Else
crr(d(str), 2) = brr(i, 1)
End If
End If
Next
With Sh3
.Range("a2:e10000").ClearContents
.Columns("a").NumberFormatLocal = "@"
.Columns("d").NumberFormatLocal = "@"
.Columns("a").HorizontalAlignment = xlLeft
.Columns("b").HorizontalAlignment = xlLeft
.Range("a2").Resize(m, 5) = crr
End With
MsgBox "ok!"
Set d = Nothing
End Sub
出现运行时错误"1004“:应用程序定义或对象定义错误。
错误定位在 .Range("a2").Resize(m, 5) = crr
求大神解答 展开
Private Sub CommandButton1_Click()
Dim arr, brr, crr
Dim d, str
Dim i, m
Set Sh1 = Sheets("资产表")
Set Sh2 = Sheets("设备表")
Set Sh3 = Sheets("结果")
Set d = CreateObject("scripting.dictionary")
With Sh1
arr = .Range("a2:e" & .Cells(.Rows.Count, 1).End(3).Row)
End With
With Sh2
brr = .Range("a2:e" & .Cells(.Rows.Count, 1).End(3).Row)
End With
ReDim crr(1 To 10000, 1 To 5)
For i = 1 To UBound(arr)
str = arr(i, 3) & "/" & arr(i, 4) & "/" & arr(i, 5)
If Not d.exists(str) Then
m = m + 1
d(str) = m
crr(m, 1) = arr(i, 1)
crr(m, 3) = arr(i, 3)
crr(m, 4) = arr(i, 4)
crr(m, 5) = arr(i, 5)
Else
crr(d(str), 1) = crr(d(str), 1) & "/" & arr(i, 1)
End If
Next
For i = 1 To UBound(brr)
str = brr(i, 3) & "/" & brr(i, 4) & "/" & brr(i, 5)
If d.exists(str) Then
If crr(d(str), 2) <> "" Then
crr(d(str), 2) = crr(d(str), 2) & "/" & brr(i, 1)
Else
crr(d(str), 2) = brr(i, 1)
End If
End If
Next
With Sh3
.Range("a2:e10000").ClearContents
.Columns("a").NumberFormatLocal = "@"
.Columns("d").NumberFormatLocal = "@"
.Columns("a").HorizontalAlignment = xlLeft
.Columns("b").HorizontalAlignment = xlLeft
.Range("a2").Resize(m, 5) = crr
End With
MsgBox "ok!"
Set d = Nothing
End Sub
出现运行时错误"1004“:应用程序定义或对象定义错误。
错误定位在 .Range("a2").Resize(m, 5) = crr
求大神解答 展开
2个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询