[英]VBA, my code is recieving a type mismatch error
收到錯誤的行是:
If rngT1 = Range("A2:D2") Then
這是完整的子例程:
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
您不能像這樣比較數組(這是您隱式所做的,因為Range.Value是范圍的默認屬性)。
不能完全確定要執行的操作,但是如果要檢查兩個引用是否引用相同的范圍,則可以執行
If Range1.Address = Range2.Address Then...
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.