简体   繁体   English

VBA,我的代码收到类型不匹配错误

[英]VBA, my code is recieving a type mismatch error

The line that is recieving the error is: 收到错误的行是:

If rngT1 = Range("A2:D2") Then

This is the full subroutine: 这是完整的子例程:

 Sub Copy_and_Paste_Other_Expenses()
     'Copy  Expense into the Payroll Journal

     Dim rngT1 As Range

        'Set the worksheet name and range appropriately
    Set rngT1 = Range(ActiveSheet.Range("A2"), ActiveSheet.Range("D2").End(xlDown))




     'Paste other expense in  in payroll Journal

    If rngT1 = Range("A2:D2") Then

       rngT1.Copy

    ActiveWorkbook.Sheets("Payroll Journal").Range("N43:Q43").PasteSpecial xlPasteValues

    ElseIf rngT1 <> ActiveWorkbook.Sheets("dat.").Range("A2:D2") Then

      rngT1.Copy

     ActiveWorkbook.Sheets("Payroll Journal").Range("N43:Q46").PasteSpecial xlPasteValues

     End If
    Rows("1:1").Select

    'Turn off Filter

    Selection.AutoFilter


End Sub

You cannot compare Arrays like that (which is what you are implicitly doing as Range.Value is the default property of a range). 您不能像这样比较数组(这是您隐式所做的,因为Range.Value是范围的默认属性)。

Not entirely sure what you are trying to do, but if you are trying to check that the two references refer to the same range you can do 不能完全确定要执行的操作,但是如果要检查两个引用是否引用相同的范围,则可以执行

If Range1.Address = Range2.Address Then...

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

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