combobox/worksheet error

depcdivr

Active Member
Joined
Jan 21, 2008
Messages
350
Office Version
  1. 365
Platform
  1. Windows
I have a userform with a combobox that I am populating with worksheet names. when the user selects a value from the combobox it will set a variable equal to the value of the combobox.

Code:
Private Sub item_Change()
Set ws = Worksheets(Me.item.Value)
icol = ws.Cells(10, Columns.count).End(xlToLeft).Offset(0, 1).Column

The problem comes when the user starts typing the value in the combobox as a short cut. If the user types in something that is not one of the choices then the program errors out on the set ws line.

I tried using
Code:
  On Error Resume Next
but it still errors out. Any suggestions on what I can do to prevent this from happening?
 

Excel Facts

Convert text numbers to real numbers
Select a column containing text numbers. Press Alt+D E F to quickly convert text to numbers. Faster than "Convert to Number"
try this

Code:
Private Sub item_Change()
    if me.item.listindex>-1 then
        Set ws = Worksheets(Me.item.Value)
        if icol = ws.Cells(10, Columns.count).End(xlToLeft).Offset(0, 1).Column
    end if
 
Upvote 0
Thanks for the help. The code did work for me but


It worked better for me to use this instead

Code:
 If Me.item.ListIndex = -1 Then
            MsgBox "select a valid item"
            Exit Sub
            
 End If
 
Upvote 0
so long as it solved the problem :)

the proverbial cat may be skinned in many ways
 
Upvote 0

Forum statistics

Threads
1,224,522
Messages
6,179,299
Members
452,904
Latest member
CodeMasterX

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