+ Reply to Thread
Results 1 to 6 of 6

Using a ComboBox in a Userform to create a dropdown list to select specific Worksheets

  1. #1
    Registered User
    Join Date
    04-21-2016
    Location
    India
    MS-Off Ver
    2007
    Posts
    3

    Using a ComboBox in a Userform to create a dropdown list to select specific Worksheets

    I need to create a dropdown list (CombobBox) in the user form that can select which worksheet the data will be entered in.

    Now, I have a few worksheets and I want to allow the user to select only the worksheets for the months (I have 12 worksheets named after each month).

    After they select the month on the drop down box in the user form, they will enter the rest of the data in the form as per normal. What I need is that this data goes to the spreadsheet for that specific month when they click the command button to insert it.

    here are codes:-

    Private Sub ComboBox1_Change()

    End Sub

    Private Sub CommandButton1_Click()
    Dim sheet As String
    sheet = ComboBox1.Value
    Worksheets(ComboBox1.Value).Activate

    Range("A3").Value = DTPicker1.Value
    Range("B3").Value = TextBox1.Text
    If OptionButton1.Value = True Then Range("D3").Value = TextBox2.Value
    If OptionButton2.Value = True Then Range("E3").Value = TextBox2.Value

    End Sub

    Private Sub TextBox1_Change()

    End Sub

    Private Sub UserForm_Click()

    End Sub

    Private Sub UserForm_Initialize()
    ComboBox1.AddItem "apolo"
    ComboBox1.AddItem "anil"
    ComboBox1.AddItem "abhay"

    End Sub

    pls reply

  2. #2
    Forum Contributor
    Join Date
    01-18-2013
    Location
    Prague
    MS-Off Ver
    Excel 2013
    Posts
    159

    Re: Using a ComboBox in a Userform to create a dropdown list to select specific Worksheets

    I presume you need something like this.


    Please Login or Register  to view this content.

  3. #3
    Registered User
    Join Date
    04-21-2016
    Location
    India
    MS-Off Ver
    2007
    Posts
    3

    Re: Using a ComboBox in a Userform to create a dropdown list to select specific Worksheets

    Thanks igormigor
    I am now able to put data in desired worksheet..

    Now I am facing some problem in data validation in combobox.
    as I am using worksheets as combobox list items. and with referene to codes given by worksheets gets acitvated.
    Now in userform if combobox is empty and I click on command button then a error msg 'subsript out of range' pops up.
    though I tried some validation methods to that combobox.

    here are code (debugging showing problem in underlined codes )

    Please Login or Register  to view this content.
    Pls reply

  4. #4
    Forum Contributor
    Join Date
    01-18-2013
    Location
    Prague
    MS-Off Ver
    Excel 2013
    Posts
    159

    Re: Using a ComboBox in a Userform to create a dropdown list to select specific Worksheets

    sorry, but I can not understand what do you want to do. can you share sample workbook.

  5. #5
    Forum Expert mikerickson's Avatar
    Join Date
    03-30-2007
    Location
    Davis CA
    MS-Off Ver
    Excel 2011
    Posts
    6,229

    Re: Using a ComboBox in a Userform to create a dropdown list to select specific Worksheets

    You need to check that something is actually selected in the ComboBox.
    You also might want to use a With End With construction.
    Also, there is no need to test if a boolean value (e.g. OptionButton1.Value) is True, one can just use that value for conditionals.

    Please Login or Register  to view this content.
    Last edited by mikerickson; 04-23-2016 at 10:43 AM.
    _
    ...How to Cross-post politely...
    ..Wrap code by selecting the code and clicking the # or read this. Thank you.

  6. #6
    Registered User
    Join Date
    04-21-2016
    Location
    India
    MS-Off Ver
    2007
    Posts
    3

    Re: Using a ComboBox in a Userform to create a dropdown list to select specific Worksheets

    Thanks mikerickson

    Its working perfect now.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Userform Combobox - select from list, store this as default each time userform loads
    By thecdnmole in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 10-19-2014, 07:48 AM
  2. [SOLVED] Select a specific value from the dropdown list and automatically diverted to another tab
    By alice2011 in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 03-14-2014, 01:52 PM
  3. Replies: 4
    Last Post: 09-10-2013, 02:11 PM
  4. [SOLVED] Excel Userform: Populate other controls (i.e. textbox & combobox) based on combobox select
    By MileHigh_PhD in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 01-22-2013, 04:50 PM
  5. Urgent: Create a Dynamic Dropdown list based on a specific criteria
    By vijaye in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 01-11-2013, 08:07 AM
  6. Replies: 3
    Last Post: 06-24-2012, 02:01 AM
  7. Need a Macro.Create new sheets from one, where need to select from a dropdown list
    By Javier091 in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 02-23-2011, 08:47 AM

Bookmarks

Posting Permissions

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

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1