更新按钮不起作用,因为类型不匹配

时间:2018-08-30 09:00:29

标签: excel excel-vba

rowselect = Search.BN.Value的类型不匹配存在错误。我想让用户编辑和更新Excel工作表,Excel工作表称为“主”。 错误消息:运行时错误“ 13”类型不匹配。

Private Sub Update_Click()

Dim Bname As String

Bname = Search.BN.Text

Sheets("MASTER").Select

Dim rowselect As Integer
Dim ans As String

rowselect = Search.BN.Value
rowselect = rowselect + 1
Rows(rowselect).Select


Sheets("MASTER").Cells(rowselect, 6) = Search.A.Text
Sheets("MASTER").Cells(rowselect, 7) = Search.Emailto.Text
Sheets("MASTER").Cells(rowselect, 8) = Search.CClist.Text
Sheets("MASTER").Cells(rowselect, 9) = Search.Emailcc.Text

rowselect = rowselect - 1

Unload Me

ans = MsgBox("S/N " & rowselect & "  Successfully Updated...Continue?", vbYesNo, "Update")
If ans = vbYes Then
    Search.Show
Else
    Sheets("MASTER").Select
End If

End Sub

1 个答案:

答案 0 :(得分:0)

也许是一个测试,看是否可以转换并声明为变量,以捕获转换时的任何错误。然后测试是否对分支程序产生了错误。下面是说明性的。

Public Sub TEST()
    Dim s As String
    'this is illustrative. You would incorporate this so  Search.BN.Value was available
    s = Search.BN.Value
    Dim rowSelect As Variant
    On Error Resume Next
    rowSelect = CLng(s)
    On Error GoTo 0

    If IsError(rowSelect) Then Exit Sub

    'Your other code......
End Sub