Results 1 to 2 of 2

Thread: adding entries into combobox with code

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Senior Member
    Join Date
    Mar 2013
    Posts
    107
    Rep Power
    12
    Last edited by DocAElstein; 07-10-2023 at 07:23 PM.

  2. #2
    Member Transformer's Avatar
    Join Date
    Mar 2012
    Posts
    91
    Rep Power
    13
    You have used userform1_Initialize and userform2_Initialize procedures to add items to Combobox2 and combobox3 but you didn't call them anywhere. Either write that code in UserForm_Initialize procedure or call these two procedures in UserForm_Initialize procedure.

    Suggestion:
    To fill the comboboxes,you add items to an array and then loop through the array to add items.You dont need to do that.It can be done in a single line.
    e.g.
    Code:
    ComboBox2.List = Worksheets("Data").Range("B2:B15").Value
    You can use the following snippet to disable the X button:

    Code:
    Private Sub UserForm_QueryClose(Cancel As Integer, CloseMode As Integer)
        If CloseMode = vbFormControlMenu Then
            Cancel = True
        End If
    End Sub
    Addendum:
    If you want to avoid all the loops while filling the comboboxes than you can use the following code:

    Code:
    Private Sub UserForm_Initialize()
      
        ComboBox1.List = Evaluate("IF(ROW(1:15),TEXT(NOW()-8 + ROW(1:15),""mm-dd-yyyy""))")
        ComboBox2.List = Worksheets("Data").Range("B2:B15").Value
        ComboBox3.List = Worksheets("Data").Range("C2:C5").Value
        
    End Sub
    Last edited by Transformer; 07-23-2013 at 02:32 PM.
    Regards,

    Transformer

Similar Threads

  1. Combobox with Dynamic Date Range
    By paul_pearson in forum Excel Help
    Replies: 5
    Last Post: 07-21-2013, 06:14 PM
  2. Combobox Not Working In Excel Workbook Shared Mode
    By peter renton in forum Excel Help
    Replies: 15
    Last Post: 06-03-2013, 01:25 PM
  3. Adding charts via code to a protected sheet
    By Rasm in forum Excel Help
    Replies: 2
    Last Post: 11-14-2012, 05:11 PM
  4. Combobox VBA update value worksheet
    By Tony in forum Excel Help
    Replies: 4
    Last Post: 10-28-2012, 12:28 AM
  5. Adding values less than zero
    By Howardc in forum Excel Help
    Replies: 3
    Last Post: 07-14-2012, 11:55 AM

Posting Permissions

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