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

Quick Sum
Select a range of cells. The total appears in bottom right of Excel screen. Right-click total to add Max, Min, Count, Average.
You've declared rowselect as String. You should declare it as Long.

Cheers!
 
Upvote 0
Thank you.

I did the change but still giving same error type now highlight this line:

VBA Code:
rowselect = Me.cmbslno.Value
 
Upvote 0
If the value is not a number, you'll get that error. What value does it contain? If the value should be a number, you should test to make sure that it's in fact a number before proceeding with the rest of the code.
 
Upvote 0
I'm assuming that cmbslno is a combobox, correct? If so, anything you enter into a combobox is actually a text value. And, if you enter a number, it's still a text value. However, it can be assigned to a variable declared as Long. In this case, the text value will be converted into a number and assigned to the variable. But if you enter a text value that cannot be converted into a number, you'll get a type mismatch error when trying to assign it to a variable declared as Long.

What value does your combobox contain when the error occurs?
 
Upvote 0
Hi,
this what the cmbslno combobox contain at the time of the error this "SCOREC"

Thank you
 

Attachments

  • combobox.PNG
    combobox.PNG
    3.4 KB · Views: 19
Upvote 0
That's because you're trying to assign a string to a variable that has been declared as Long.

I see that first you're trying to assign a string to your variable, and then you're trying to increment it. So it's confusing.

Can you explain what it is you're trying to do?
 
Upvote 0
I am try to update a field in the userform the payment term in the vendor NET15 when click ok then get the error here is the code have now for
the update:

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 Long
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
 
Upvote 0
It looks like you would like to search Column A in your sheet called DISTRIBUTION_SET_G-L_CODING for the value entered in cmbslno, and then update that row based on the values from your textboxes on your userform. Is this correct?
 
Upvote 0

Forum statistics

Threads
1,223,911
Messages
6,175,325
Members
452,635
Latest member
laura12345

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