Run-time error 13

josros60

Well-known Member
Joined
Jun 27, 2010
Messages
786
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

Can a formula spear through sheets?
Use =SUM(January:December!E7) to sum E7 on all of the sheets from January through December
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
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,224,827
Messages
6,181,197
Members
453,022
Latest member
RobertV1609

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