Run-time error '9' Help

Pookiemeister

Well-known Member
Joined
Jan 6, 2012
Messages
626
Office Version
  1. 365
  2. 2010
Platform
  1. Windows
On my userform I have two combo boxes and one read-only textbox. In the first text box the user selects a machine production line. Based on the machine production line selected, the second combo box will populate with the products that are ran on that line which is located on a spreadsheet named for that line. The problem that throws a "Run-time error '9': Subscript out of range" is when the user exits the first combobox and makes a selection from the second combobox and then decides to go back to the first combo box. The code that is highlighted when I select the Debug option is shown below.

By the way, the names associated with above boxes are:
First combobox Name=cmbSDPFLine
Second combobox Name=cmbPrdCde
Read Only Textbox Name=txtbxPrdctNm

Code:
Private Sub cmbPrdCde_Change()    
            Me.txtbxPrdctNm.Value = Replace(Split(Me.cmbPrdCde.Value, "(")(1), ")", vbNullString)

End Sub
Thank You.

NOTE: As long as the user continues through the form as normal and doesn't return back to the combo boxes, no error is thrown.
 
Last edited:

Excel Facts

What did Pito Salas invent?
Pito Salas, working for Lotus, popularized what would become to be pivot tables. It was released as Lotus Improv in 1989.
How about
Code:
Private Sub cmbPrdCde_[COLOR=#0000ff]Click[/COLOR]()    
            Me.txtbxPrdctNm.Value = Replace(Split(Me.cmbPrdCde.Value, "(")(1), ")", vbNullString)

End Sub
As I originally suggested.
 
Upvote 0
But I would have to put this code inside the click event in both combo boxes. Right?
Because if I add another textbox below the combo boxes, regardless of which combo box I click on, it still throws that error message.
I added another text box below the combo boxes to test and see which combo box threw the error code, but they both did.
 
Last edited:
Upvote 0
After putting the code where you suggested, I still get the same error message.
 
Upvote 0
Did you remove the Change event?
Did you click cmbPrdCde while cmbPrdCde was empty?
 
Upvote 0
No I didn't remove the change event and that was why it still gave that same error message. I found that out after I removed it and reran the code. Thanks again.
 
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,177
Members
453,021
Latest member
Justyna P

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