将DBF转换为xls会影响macros吗?

如果数据是手动input到电子表格中,我有这个代码运行没有问题。 手动键入显然不是最有效的,我从数据库系统接收数据输出到一个dbf文件。

当我将dbf转换为excel并将数据粘贴到工作表中时,我需要运行macros我得到一个types不匹配错误(在**之间)

Sub TimeDifference() ActiveWorkbook.Sheets("Avg Downtime").Select Range("G3:H500").Select Selection.ClearContents i = 3 j = i + 1 For i = 3 To 500 If Cells(i, "A").Value = Cells(j, "A").Value Then 'checks if TagID are the same If Cells(i, "C").Value > 0 And Cells(j, "D").Value > 0 Then 'checks if there has been a complete alarm on/off process *Cells(j, "G").Value = Cells(j, "B").Value - Cells(i, "B").Value* 'calculates downtime End If End If j = j + 1 Next i 

这只是一个简单的减法,当我手动做这个没有问题。 我不知道我能做些什么来解决这个问题。

B很可能是一个空值或非数值,你试图用它来做math运算。

尝试这样的事情。

 Sub TimeDifference() Dim ws As Excel.Worksheet Dim iRow As Integer Set ws = ActiveWorkbook.Sheets("Avg Downtime") ws.Activate iRow = 3 ws.Range("A" & lRow).Activate Do While iRow <= 500 If ws.Range("A" & iRow).Value = ws.Range("A" & iRow + 1).Value Then If ws.Range("C" & iRow).Value > 0 And ws.Range("D" & iRow + 1).Value > 0 Then if isnumeric(ws.Range("B" & iRow + 1).Value) = true and isnumeric(ws.Range("B" & iRow).Value) = true then ws.Range("G" & iRow + 1).Value = ws.Range("B" & iRow + 1).Value - ws.Range("B" & iRow).Value end if End If End If iRow = iRow + 1 Loop End sub