EXCEL VBA类型不匹配错误“13”使用带日期的变量

时间:2016-02-27 18:43:47

标签: excel vba excel-vba

也许有人可以帮助我,因为我无法找到错误。我在标有** ... **的行上遇到了类型不匹配错误13。两个变量都包含日期,并声明为日期。如果我调试我的脚本,它显示dateVisitPtLog = 27/01/2016和dateVisitReport = 1/02/2016。为什么我会收到错误?

Thx

Dim lastRowUsedControlDateNoMatch As Long             
Dim lastRowUsedControlVisitNoDate As Long                    
Dim rowReport As Long    
Dim nrVisitReport As String
Dim patientNrReport As String                           
Dim dateVisitReport As Date                                                
Dim nrVisitPtLog As String                      
Dim dateVisitPtLog As Date                      
Dim rowPtLog As Long
Dim lastRowUsedPtLog As Long 
Dim patientNrPtLog As String

For rowPtLog = 2 To lastRowUsedPtLog

    Sheets("PtLog").Select
    patientNrPtLog = Cells(rowPtLog, 5).Value
    nrVisitPtLog = Cells(1, 8).Value
    dateVisitPtLog = Cells(rowPtLog, 8).Value

    Sheets("Report").Select

    For rowReport = 2 To lastRowUsedReport

        Sheets("Report").Select
        dateVisitReport = Sheets("Report").Cells(rowReport, 6)
        patientNrReport = Sheets("Report").Cells(rowReport, 2)
        nrVisitReport = Sheets("Report").Cells(rowReport, 4)


        If patientNrPtLog = patientNrReport And nrVisitPtLog = nrVisitReport Then

            If dateVisitPtLog <> dateVisitReport Then

                ** If dateVisitPtLog <> "" And dateVisitReport = "" Then **

                    Sheets("CONTROL").Select
                    lastRowUsedControlVisitNoDate = lastRowUsedControlVisitNoDate + 1
                    Cells(lastRowUsedControlVisitNoDate, 2) = patientNrPtLog
                    Cells(lastRowUsedControlVisitNoDate, 3) = nrVisitPtLog

                End If


                If dateVisitPtLog = "" And dateVisitReport <> "" Then

                    Sheets("PtLog").Cells(rowPtLog, 8) = dateVisitReport
                    With Sheets("PtLog").Cells(rowPtLog, 8).Font
                        .Color = -1003520
                        .TintAndShade = 0
                    End With

                End If


                If dateVisitPtLog <> "" And dateVisitReport <> "" Then

                    Sheets("CONTROL").Select
                    lastRowUsedControlDateNoMatch = lastRowUsedControlDateNoMatch + 1
                    Cells(lastRowUsedControlDateNoMatch, 9) = patientNrPtLog
                    Cells(lastRowUsedControlDateNoMatch, 10) = nrVisitPtLog
                    Cells(lastRowUsedControlDateNoMatch, 11) = dateVisitReport
                    Cells(lastRowUsedControlDateNoMatch, 12) = dateVisitPtLog

                End If

            End If

        End If

    Next rowReport

Next rowPtLog

0 个答案:

没有答案