类型不匹配,运行时错误13

时间:2011-07-13 06:07:00

标签: excel vba

我在if iRowValue null检查时遇到以下类型不匹配错误

我要做的是确定表格中是否已存在该值,然后更新该列,或者在末尾附加。

Public iRowValue As Long

Public iRow As Long

----------

Private Sub Update_Click()
Dim Rng As Range
Dim FindString1 as String


With ws.Range("A:A")
         Set Rng = .Find(What:=FindString1, _
                         After:=.Cells(.Cells.Count), _
                         LookIn:=xlValues, _
                         LookAt:=xlWhole, _
                         SearchOrder:=xlByRows, _
                         SearchDirection:=xlNext, _
                         MatchCase:=False)

         If Rng Is Nothing Then
            MsgBox "Name does not Exists"
         Else
            iRowValue = Rng.Row
         End If
    End With

**If iRowValue <> "" Then**

iRow = iRowValue

Else

iRow = ws.Cells(Rows.Count, 1) _
  .End(xlUp).Offset(1, 0).Row
End If

ws.Cells(iRow, 1).Value = Me.FirstName.Value

ws.Cells(iRow, 2).Value = Me.LastCode.Value

End Sub

1 个答案:

答案 0 :(得分:1)

iRowValue被声明为Long,然后尝试将它与String进行比较 - 这是无效的。只需与0比较就可以了。