+ Reply to Thread
Results 1 to 2 of 2

Filling combo box

  1. #1
    Registered User
    Join Date
    07-04-2014
    Location
    India
    MS-Off Ver
    2010
    Posts
    1

    Filling combo box

    I am entirely new and have very basic knowledge of vb excel. With the help of example given at internet, I have made an application in vb excel. I have used many combo boxes. For example combobox1 is for name of employees, combobox 2 is for "Name of destination" and so on. I have separate excel sheet for each combobox from where I want that for each combo box the value/text be fetched from the relevant excel sheet. I have used the following codes for entire application.

    Private Sub ComboBox1_Change()

    End Sub

    Private Sub CommandButton3_Click()
    Unload Me
    End Sub
    Private Sub CommandButton2_Click()
    Call UserForm_Initialize
    End Sub
    Private Sub DTPicker1_CallbackKeyDown(ByVal KeyCode As Integer, ByVal Shift As Integer, ByVal CallbackField As String, CallbackDate As Date)
    End Sub

    Private Sub CommandButton1_Click()
    Dim RowCount As Long
    Dim ctl As Control
    ' Check user input

    If Me.ComboBox1.Value = "" Then
    MsgBox "Please choose Executive's Name.", vbExclamation, "Station Leave Application"
    Me.ComboBox1.SetFocus
    Exit Sub
    End If

    If Me.ComboBox2.Value = "" Then
    MsgBox "Please choose Your Designation", vbExclamation, "Station Leave Application"
    Me.ComboBox1.SetFocus
    Exit Sub
    End If

    If Me.ComboBox3.Value = "" Then
    MsgBox "Please choose Your Employee No.", vbExclamation, "Station Leave Application"
    Me.ComboBox1.SetFocus
    Exit Sub
    End If

    If Me.ComboBox4.Value = "" Then
    MsgBox "Please choose Name of your Division", vbExclamation, "Station Leave Application"
    Me.ComboBox1.SetFocus
    Exit Sub
    End If

    If Me.ComboBox5.Value = "" Then
    MsgBox "Please choose Name of your Reporting Officer", vbExclamation, "Station Leave Application"
    Me.ComboBox1.SetFocus
    Exit Sub
    End If

    If Me.DTPicker1.Value = "" Then
    MsgBox "Please enter a Date.", vbExclamation, "Station Leave Application"
    Me.ComboBox1.SetFocus
    Exit Sub
    End If

    If Me.TextBox1.Value = "" Then
    MsgBox "Please Enter Time in HH:MM", vbExclamation, "Station Leave Application"
    Me.ComboBox1.SetFocus
    Exit Sub
    End If

    If Me.ComboBox6.Value = "" Then
    MsgBox "Please choose AM/PM", vbExclamation, "Station Leave Application"
    Me.ComboBox1.SetFocus
    Exit Sub
    End If

    If Me.ComboBox7.Value = "" Then
    MsgBox "Please enter Destination", vbExclamation, "Station Leave Application"
    Me.ComboBox1.SetFocus
    Exit Sub
    End If



    If Me.DTPicker2.Value = "" Then
    MsgBox "Please enter a Date.", vbExclamation, "Station Leave Application"
    Me.ComboBox1.SetFocus
    Exit Sub
    End If

    If Me.TextBox2.Value = "" Then
    MsgBox "Please Enter Time in HH:MM", vbExclamation, "Station Leave Application"
    Me.ComboBox1.SetFocus
    Exit Sub
    End If




    If Me.ComboBox8.Value = "" Then
    MsgBox "Please choose AM/PM", vbExclamation, "Station Leave Application"
    Me.ComboBox1.SetFocus
    Exit Sub
    End If

    If Me.ComboBox9.Value = "" Then
    MsgBox "Please enter reason of station leave", vbExclamation, "Station Leave Application"
    Me.ComboBox1.SetFocus
    Exit Sub
    End If

    If Me.ComboBox10.Value = "" Then
    MsgBox "Please enter recommedation comment", vbExclamation, "Station Leave Application"
    Me.ComboBox1.SetFocus


    Exit Sub
    End If


    'transfer to spreadsheet

    Worksheets("Station Leave Application").Select


    'go to first blank cell

    Cells.Range("B4").Select

    ActiveCell.Offset(0, 0).Select

    ActiveCell.Value = Me.ComboBox1.Value

    ActiveCell.Offset(0, 0).Value = Me.ComboBox1.Value
    ActiveCell.Offset(1, 0).Value = Me.ComboBox2.Value
    ActiveCell.Offset(2, 0).Value = Me.ComboBox3.Value
    ActiveCell.Offset(3, 0).Value = Me.ComboBox4.Value
    ActiveCell.Offset(4, 0).Value = Me.ComboBox5.Value
    ActiveCell.Offset(5, 0).Value = DateValue(Me.DTPicker1.Value)
    ActiveCell.Offset(5, 1).Value = Me.TextBox1.Value
    ActiveCell.Offset(5, 2).Value = Me.ComboBox6.Value
    ActiveCell.Offset(6, 0).Value = Me.ComboBox7.Value
    ActiveCell.Offset(7, 0).Value = DateValue(Me.DTPicker2.Value)
    ActiveCell.Offset(7, 1).Value = Me.TextBox2.Value
    ActiveCell.Offset(7, 2).Value = Me.ComboBox8.Value
    ActiveCell.Offset(8, 0).Value = Me.ComboBox9.Value
    ActiveCell.Offset(14, 0).Value = Me.ComboBox10.Value


    'hide form

    Unload Me


    End Sub

    Private Sub Label10_Click()

    End Sub

    Private Sub TextBox1_Change()

    End Sub

    Private Sub UserForm_Initialize()
    'Empty TextBox1
    TextBox1.Value = ""
    'Empty TextBox2
    TextBox2.Value = ""

    'Empty ComboBox1
    ComboBox1.Clear

    'Fill ComboBox1
    With ComboBox1
    .AddItem "---Select---" (I do not want to add so many names here, instead I want to use an excel sheet where all
    such names have been kept. When I click ombobox1 in the application all names of this list
    should appeared in the drop down list and I should be able to pick anyone from this list.)
    .AddItem "VIRENDER SALMAN, C.E.(Dam)"
    .AddItem "M K GOEL, C.E.(HQ)"
    .AddItem "D C TRIPATHI, Chief (Geo)"
    .AddItem "K K SRIVASTAVA, C.E.(PH)"
    .AddItem "DURGESH KUMAR, SM(IT&C)"
    .AddItem "SURENDRA JOSHI, Manager(Civil)"
    .AddItem " N.M.GUPTA, Manager(M) "
    .AddItem "DEEPAK SANADHYA, D.M.(C)"
    .AddItem "JAYANTI MALLA PESHIN, D.M.(IT)"
    .AddItem "SANJAY PRATAP VIKRAM, A.M.(Civil)"

    End With

    'Empty ComboBox2
    ComboBox2.Clear

    'Fill ComboBox2
    With ComboBox2
    .AddItem "---Select---"


    End With

    'Empty ComboBox3
    ComboBox3.Clear

    'Fill ComboBox3
    With ComboBox3
    .AddItem "---Select---"

    End With

    'Empty ComboBox4
    ComboBox4.Clear


    'Fill ComboBox4
    With ComboBox4
    .AddItem "---Select---"
    .AddItem "Civil"
    .AddItem "Electrical"
    .AddItem "Mechanical"
    .AddItem "Finance"
    .AddItem "Stores & Disposal"
    .AddItem "HR"
    .AddItem "Environment"
    .AddItem "CE Office"
    .AddItem "Electrical & Stores"
    .AddItem "IT"
    .AddItem "IT & Communication"
    .AddItem "Electrical & Communication"
    .AddItem "Library"
    .AddItem "Hindi"
    .AddItem "Medical"
    .AddItem "Township"
    .AddItem "Water Supply"
    .AddItem "Proc & contract"
    .AddItem "Planning"
    .AddItem "QC &A"
    .AddItem "CED"


    End With

    'Empty ComboBox5
    ComboBox5.Clear

    'Fill ComboBox5
    With ComboBox5
    .AddItem "---Select---"

    End With
    'Empty ComboBox6
    ComboBox6.Clear

    'Fill ComboBox6
    With ComboBox6
    .AddItem "---Select---"
    .AddItem "AM"
    .AddItem "PM"

    End With
    'Empty ComboBox7
    ComboBox7.Clear

    'Fill ComboBox7
    With ComboBox7
    .AddItem "---Select---"

    End With
    'Empty ComboBox8
    ComboBox8.Clear

    'Fill ComboBox8
    With ComboBox8
    .AddItem "---Select---"
    .AddItem "AM"
    .AddItem "PM"

    End With
    'Empty ComboBox9
    ComboBox9.Clear

    'Fill ComboBox9
    With ComboBox9
    .AddItem "---Select---"

    End With
    'Empty ComboBox10
    ComboBox10.Clear

    'Fill ComboBox10
    With ComboBox10
    .AddItem "---Select---"
    .AddItem "Station leave granted"
    .AddItem "Recommeded for grant of station leave"
    .AddItem "Station leave not granted"
    .AddItem "Station leave can not be reommended"
    End With
    End Sub

    Private Sub UserForm_Click()

    End Sub


    To make you understand my problem I am attaching the application. Kindly guide me how to do the necessary corrections in my application.
    Regards

    N.M.GUPTA
    Attached Files Attached Files

  2. #2
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,646

    Re: Filling combo box

    Your post does not comply with Rule 3 of our Forum RULES. Use code tags around code.

    Posting code between [CODE]Please [url=https://www.excelforum.com/login.php]Login or Register [/url] to view this content.[/CODE] tags makes your code much easier to read and copy for testing, it also maintains VBA formatting.

    Highlight your code and click the # icon at the top of your post window. More information about these and other tags can be found here



    (This thread should receive no further responses until this moderation request is fulfilled, as per Forum Rule 7)
    If posting code please use code tags, see here.

+ 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. Filling Combo boxes based on the value of one combo box
    By KSChan in forum Excel Formulas & Functions
    Replies: 2
    Last Post: 07-01-2014, 12:48 AM
  2. [SOLVED] filling the combo boxes
    By Quicksnot in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 03-02-2014, 01:39 AM
  3. Filling Combo Box
    By yay_excel in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 08-17-2011, 01:38 PM
  4. Filling a combo box from the spreadsheet
    By rob0r in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 02-16-2009, 10:35 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