Consulting

Results 1 to 16 of 16

Thread: Sub Not Defined error when using a renamed combobox

  1. #1
    VBAX Regular
    Joined
    Nov 2018
    Location
    London, U.K.
    Posts
    99
    Location

    Sub Not Defined error when using a renamed combobox

    I renamed a combobox in my Userform, however when I'm running code I get a 'sub not defined' error. I have no idea what this means or how to fix it.

    Here is my code:

    Private Sub Userform_Initialise ()

    ComboBox("Scheme").List = Worksheets("Validation").Range("A2:A4").Value

    End Sub

  2. #2
    Could you please attach a sample of your workbook

  3. #3
    VBAX Guru Kenneth Hobs's Avatar
    Joined
    Nov 2005
    Location
    Tecumseh, OK
    Posts
    4,956
    Location
    Private Sub UserForm_Initialize()

  4. #4
    VBAX Regular
    Joined
    Nov 2018
    Location
    London, U.K.
    Posts
    99
    Location
    Quote Originally Posted by Kenneth Hobs View Post
    Private Sub UserForm_Initialize()
    I changed that but still no luck.

  5. #5
    VBAX Regular
    Joined
    Nov 2018
    Location
    London, U.K.
    Posts
    99
    Location

    Sample workbook attached

    As requested
    Attached Files Attached Files

  6. #6
    VBAX Master Aflatoon's Avatar
    Joined
    Sep 2009
    Location
    UK
    Posts
    1,720
    Location
    There is no userform in that workbook.

    Combobox is not a valid property of a form, so I suspect you need:

    Private Sub Userform_Initialize()
    
    Scheme.List = Worksheets("Validation").Range("A2:A4").Value
    
    
    End Sub
    Assuming the control is named Scheme.
    Be as you wish to seem

  7. #7
    I don't see any code or userform in the workbook you posted.

  8. #8
    Perhaps he forgot to save as macro enabled workbook

  9. #9
    VBAX Regular
    Joined
    Nov 2018
    Location
    London, U.K.
    Posts
    99
    Location

    Wrong file attached.

    Attached the wrong file, this one contains the form.
    Attached Files Attached Files

  10. #10
    VBAX Master Aflatoon's Avatar
    Joined
    Sep 2009
    Location
    UK
    Posts
    1,720
    Location
    Not sure that helps either as it doesn't have the code you posted initially, or any controls called Scheme in it.
    Be as you wish to seem

  11. #11
    Are you sure this new file pertains to the problem you are having? I don't see any combobox named "Scheme" or any construct like this
    ComboBox("Scheme").List = Worksheets("Validation").Range("A2:A4").Value
    or even the word "scheme". The error it produces when I run it, is Runtime error 70 - permission denied. The way to fix that error is to clear the rowsource property before attempting to assign values to list.
    Private Sub UserForm_Initialize()
        ComboBox1.RowSource = ""
        ComboBox1.List = Worksheets("Validation").Range("B2:B88").Value
    End Sub

  12. #12
    VBAX Regular
    Joined
    Nov 2018
    Location
    London, U.K.
    Posts
    99
    Location
    I was trying to correct the error, so I temporarily changed the combo box name to ComboBox1A. When I inserted the box I renamed it "Scheme". The first combo box on the 2nd row of the form is comboBox1

  13. #13
    VBAX Guru Kenneth Hobs's Avatar
    Joined
    Nov 2005
    Location
    Tecumseh, OK
    Posts
    4,956
    Location
    To repeat what rlv said in another way, I generally remove the value in the RowSource property for that control before using the List property. Do that or as rlv showed in code.

    Private Sub UserForm_Initialize()  
      With Worksheets("Validation")
        ComboBox1.List = .Range("B2", .Cells(Rows.Count, "B").End(xlUp)).Value
      End With
    End Sub

  14. #14
    VBAX Master Aflatoon's Avatar
    Joined
    Sep 2009
    Location
    UK
    Posts
    1,720
    Location
    If the control was named Scheme, then as I said earlier, the code would be:

    Scheme.List = Worksheets("Validation").Range("A2:A4").Value
    Be as you wish to seem

  15. #15
    VBAX Regular
    Joined
    Nov 2018
    Location
    London, U.K.
    Posts
    99
    Location

    Sub Not Defined Error

    When I use the clear row source property code as above I get an Object Required error.

    Scheme.RowSource = ""
    When I use

    With Worksheets("Validation")
        ComboBox1.List = .Range("B2", .Cells(Rows.Count, "B").End(xlUp)).Value
      End With
    Everything works ok!

  16. #16
    VBAX Master Aflatoon's Avatar
    Joined
    Sep 2009
    Location
    UK
    Posts
    1,720
    Location
    Then you didn't name the control Scheme.
    Be as you wish to seem

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •