簡體   English   中英

類型:不匹配 VBA 錯誤 - 代碼無效

[英]Type: Mismatch VBA Error - Code not working

我在下面的代碼中不斷收到類型不匹配錯誤(在行旁邊指示),有趣的是宏正在運行,但是當我在另一台計算機上通過電子郵件將其發送給自己時,它崩潰了。 知道如何解決這個問題嗎?

為了提供背景,該宏適用於將問題記錄到不同選項卡(取決於問題是什么)的用戶表單。 當問題被標記為完成時,問題將移至“5. 完成並已驗證”選項卡,為該行分配一個數字,並添加一個列,說明完成該問題需要多少天。 當問題從源選項卡中移出時,它會被復制、刪除,然后添加到 5. Complete and Verified 選項卡中。

Option Explicit

Sub Complete()

Dim sourceWS As Worksheet
Set sourceWS = ActiveSheet
Dim destWS As Worksheet
Set destWS = ThisWorkbook.Worksheets("5. Complete & Verified")

Dim RowCountS, RowCountD As Long

Dim intLastRowSrc As Long
RowCountS = ActiveSheet.Rows.Count
intLastRowSrc = sourceWS.Cells(RowCountS, 1).End(xlUp) + 1'Type Mistmatch

Dim intLastRowSDes As Long
RowCountD = Worksheets("5. Complete & Verified").Rows.Count
intLastRowSDes = destWS.Cells(RowCountD, 2).End(xlUp) + 1 'Type Mismatch

Dim r As Long

Dim iRow2 As Long
iRow2 = Application.WorksheetFunction.CountA(Sheets("5. Complete & Verified").Range("B:B")) + 1

Dim iRow3 As Long
iRow3 = Application.WorksheetFunction.CountA(sourceWS.Range("A:A")) + 1


Dim LastRow4 As Long
Dim LastRow5 As Long


For r = intLastRowSrc To 2 Step -1
        If sourceWS.Cells(r, "R") = "Complete & Verified" Then
            intLastRowSDes = destWS.Cells(RowCountD, 2).End(xlUp) + 2
            destWS.Range("C" & intLastRowSDes & ":S" & intLastRowSDes).Value = sourceWS.Range("B" & r & ":R" & r).Value
            sourceWS.Rows(r).Delete
            destWS.Cells(intLastRowSDes, 1) = sourceWS.Name ' Adding tab name as the Payer
            destWS.Cells(iRow2, 2) = iRow2 - 1 ' Numbering the rows in order instead of copying number from payer tab
            
            'Adding in Column for Days to Complete
            Worksheets("5. Complete & Verified").Cells(2, 20) = "=IF(RC[-3]="""",0,RC[-3]-RC[-9])"
            LastRow5 = Worksheets("5. Complete & Verified").Range("A1").End(xlDown).Row 'last row filled number row number not cell value 'need to copy before pasting
            Worksheets("5. Complete & Verified").Range("T2").Copy
            Worksheets("5. Complete & Verified").Range("T2" & ":" & "T" & LastRow5).PasteSpecial (xlPasteFormulas) 'paste formulas
            Worksheets("5. Complete & Verified").Range("A1") = "Payor"
            Worksheets("5. Complete & Verified").Range("A1") = "Payor"
            Worksheets("5. Complete & Verified").Activate
            Range("A1").Select
            ActiveWindow.ScrollRow = 1
            ActiveWindow.ScrollColumn = 1

            'Renumbering the No. Column on the Payer Tab
            sourceWS.Activate
            
            If IsEmpty(sourceWS.Range("A2")) = False Then
                LastRow4 = Range("A1").End(xlDown).Row 'last row filled number row number not cell value 'need to copy before pasting
                If (LastRow4 = 2) Then
                sourceWS.Range("A2") = 1
                Else
                sourceWS.Range("A2") = "=ROW()-1"
                sourceWS.Range("A2").Copy
                sourceWS.Range("A2" & ":" & "A" & LastRow4).FillDown 'paste formula
                End If
                sourceWS.Calculate
                sourceWS.Range("A2" & ":" & "A" & LastRow4).Copy
                sourceWS.Range("A2" & ":" & "A" & LastRow4).PasteSpecial Paste:=xlPasteValues
                Application.CutCopyMode = False
                Range("A2").Select
            
    End If
    End If

Next



Exit Sub

End Sub

sourceWS.Cells(RowCountS, 1).End(xlUp) 返回一個范圍引用,您不能將數字添加到范圍。 嘗試: sourceWS.Cells(RowCountS, 1).End(xlUp).Row() + 1 你應該有一個有效的行號。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM