简体   繁体   English

如何修复VBA代码中的“需要对象”错误?

[英]How to fix “Object required” error in VBA code?

I have a current code that is supposed to take values from sheet1 and sheet2 and output them into sheet3. 我有一个当前代码,应该从sheet1和sheet2中获取值,并将其输出到sheet3中。 The only problem I'm having with this code is that I keep getting "Object required" errors on the : 我在这段代码中遇到的唯一问题是,我不断在上出现“ Object required”错误:

With sheets3
        .Rows(.Cells(.Rows.Count, 1).End(xlUp).Row) = sheets1.Rows(myrow)
        End With

specifically the .Rows line 特别是.rows行

Here is the full code: 这是完整的代码:

Sub qwerty()
Dim isamatch As Boolean
For myrow = 1 To Sheet1.Cells(Rows.Count, 1).End(xlUp).Row
    isamatch = True
    For mycol = 1 To Sheet1.Cells(myrow, "ZZ").End(xlToLeft).Column + 1
        If Sheet1.Cells(myrow, mycol).Value <> Sheet2.Cells(myrow, mycol).Value Then isamatch = False
    Next mycol
    If isamatch Then
        With sheets3
        .Rows(.Cells(.Rows.Count, 1).End(xlUp).Row) = sheets1.Rows(myrow)
        End With
    End If
Next myrow
End Sub

Changed sheets to sheet 将工作sheets更改为工作sheet

Sub qwerty()
Dim isamatch As Boolean
For myrow = 1 To Sheet1.Cells(Rows.Count, 1).End(xlUp).Row
    isamatch = True
    For mycol = 1 To Sheet1.Cells(myrow, "ZZ").End(xlToLeft).Column + 1
        If Sheet1.Cells(myrow, mycol).Value <> Sheet2.Cells(myrow, mycol).Value Then isamatch = False
    Next mycol
    If isamatch Then
        With sheet3
        .Rows(.Cells(.Rows.Count, 1).End(xlUp).Row) = sheet1.Rows(myrow)
        End With
    End If
Next myrow
End Sub

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM