This is a discussion on User Form won't Initialize. Run time error within the Excel Questions forums, part of the Question Forums category; Hello everyone: I am having an issue with my form initializing. The form name is frmAddRepresentative and has a combo ...
I am having an issue with my form initializing. The form name is frmAddRepresentative and has a combo box called cboRepName. The code below should run when the form initializes. But I am getting a run time error -2147467259 (80004005). Unespecified error. Not much help from that.
Also, I change UserForm_Initialize to frmAddRepresentative_Initialize, the form opens but I get a subscript out of range on the Me.cboRepName references.
I can't figure out what I am doing wrong.
Code:Option Explicit Private Sub UserForm_Initialize() Dim ws As Worksheet Set ws = Worksheets("Rep Information") UpdateComboLists Me.cboRepName.SetFocus End Sub Private Sub UpdateComboLists() Dim cName As Range Dim ws As Worksheet Set ws = Worksheets("Rep Information") Me.cboRepName.Clear For Each cName In ws.Range("repName") With Me.cboRepName .AddItem cName.Value .List(.ListCount - 1, 1) = cName.Offset(0, 1).Value End With Next cName End Sub
Excel MVP 2011-2014
Thank you, I did as you said and the error seems to be in the For Loop,
For Each cName In ws.Range("repName")
But I can't figure out why there would be an error. I named the variable rngName and I am using a named range repName. This should be working.
Are there any values in repName?
Have you previously used RowSource to populate the listbox?
If posting code please use code tags.
Thanks, just for kicks I changed the name of my named range from repName to Names and it works fine now. There must be something with the naming convention.