Run-time error 13

josros60

Well-known Member
Joined
Jun 27, 2010
Messages
780
Office Version
  1. 365
Hi,

have the code below giving me run-time error 13 type mismatch and highlighting this line:

VBA Code:
rowselect = rowselect + 1

Complete code:

VBA Code:
Private Sub cmdupdate_Click()
If Me.cmbslno.Value = "" Then
MsgBox "SAGEID Can Not be Blank!!!", vbExclamation, "SAGEID"
Exit Sub
End If
SLNo = Me.cmbslno.Value
Sheets("DISTRIBUTION_SET_G-L_CODING").Select
Dim rowselect As String
Dim msg As String
Dim ans As String
rowselect = Me.cmbslno.Value
rowselect = rowselect + 1
Rows(rowselect).Select
Cells(rowselect, 2) = Me.txtvendor.Value
Cells(rowselect, 3) = Me.txtcurrency.Value
Cells(rowselect, 4) = Me.txtbPO.Value
Cells(rowselect, 5) = Me.txtapprover.Value
Cells(rowselect, 6) = Me.txtGLcode.Value
Cells(rowselect, 7) = Me.txtLineDes.Value
Cells(rowselect, 8) = Me.txttax.Value
Cells(rowselect, 9) = Me.txtAccTer.Value
Cells(rowselect, 10) = Me.txtOrgUnit.Value

rowselect = rowselect - 1
msg = "SAGEID " & rowselect & "  Successfully Updated...Continue?"
Unload Me
ans = MsgBox(msg, vbYesNo, "Update")
If ans = vbYes Then
UserForm1.Show
Else
Sheets("DISTRIBUTION_SET_G-L_CODING").Select
End If
End Sub

Thank you,
 

Excel Facts

Did you know Excel offers Filter by Selection?
Add the AutoFilter icon to the Quick Access Toolbar. Select a cell containing Apple, click AutoFilter, and you will get all rows with Apple
Try something like this . . .

VBA Code:
With Sheets("DISTRIBUTION_SET_G-L_CODING")

    Dim target As Range
    Set target = .Range("A:A").Find(what:=SLNo, after:=.Range("A1"), LookIn:=xlValues, lookat:=xlWhole, searchdirection:=xlNext, MatchCase:=False)
   
    If Not target Is Nothing Then
        .Cells(target.Row, 2) = Me.txtvendor.Value
        .Cells(target.Row, 3) = Me.txtcurrency.Value
        .Cells(target.Row, 4) = Me.txtbPO.Value
        .Cells(target.Row, 5) = Me.txtapprover.Value
        .Cells(target.Row, 6) = Me.txtGLcode.Value
        .Cells(target.Row, 7) = Me.txtLineDes.Value
        .Cells(target.Row, 8) = Me.txttax.Value
        .Cells(target.Row, 9) = Me.txtAccTer.Value
        .Cells(target.Row, 10) = Me.txtOrgUnit.Value
    Else
        'SLNo not found, do something else
        '
        '
    End If
   
End With

Notice that there's no need to select your worksheet first before searching and updating it.

Hope this helps!
 
Upvote 0
Solution
To stop getting that error when updating a record in any field .

Thank you
 
Upvote 0
Actually, the code I posted in my last post will avoid the error. It searches Column A for the combobox value. If it finds it, the corresponding row is updated. If it doesn't find it, the else statement is executed. I left it blank since I couldn't be sure what you want done in that case.

Have you tried it?
 
Upvote 0
I'm really sorry sorry didn't see you posted it will try it and let you know.

My mistake
Thank you so much.
 
Upvote 0

Forum statistics

Threads
1,214,904
Messages
6,122,169
Members
449,070
Latest member
webster33

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top