输入比较单元格值的不匹配错误

时间:2017-12-03 23:22:16

标签: excel-vba type-mismatch vba excel

我想比较同一工作表中的两个单元格,包括函数/计算结果与相应列中的单元格。我得到一个类型不匹配错误就像我要求比较单元格值一样。你能帮忙吗?

Sub CorrAct()  
Dim x As Workbook  
Dim y As Workbook  
Dim Rng As Range  
Dim QA As Worksheet  
Dim Corr_Act As Worksheet  
Dim Expected As Range  
Dim Data As Range  

On Error GoTo 0

'## Open both workbooks first:  
Set x = ThisWorkbook  
Set y = Workbooks.Open("file:///###")   

Set QA = x.Sheets("QA ab SAB-100 ####")
Set Corr_Act = y.Sheets("Corrective Actions Register")

Set Expected = QA.Range("V10")
Set Data = QA.Range(QA.Range("F10"), QA.Range("F10").End(xlDown))


'Compare data to expected values  
For Each cell In Data.Cells
If Data.Value > Expected.Value Then    <<<ERROR HERE


'Now, transfer values from x to y:  
Corr_Act.Range("A4").Value = QA.Range("A1")

End If

Next cell  
End Sub

0 个答案:

没有答案