Consulting

Results 1 to 3 of 3

Thread: Filling Cells with a TextBox matching a ComboBox - VBA Code

  1. #1
    VBAX Newbie
    Joined
    Nov 2013
    Posts
    4
    Location

    Question Filling Cells with a TextBox matching a ComboBox - VBA Code

    Afternoon all,

    Is this even possible?! I'm quite new to VBA in excel and I was wondering if something like this was possible in a userform? I've tried all kinds of things and i've got nowhere near what i want

    I currently have a userform setup. The ComboBox holds the data that the user would select and next to it are 7 (Each day of the week) textbox's which i'd like the user to manually enter into (These would be names) Each TextBox is assigned that days tag.

    In the attached file, the yellow cells are an example - So once the userform is opened, the user would select 07SA001 (From the ComboBox) and enter names in Tue-Wed-Thu-Fri-Sat and then click "Add names" Which would add the names to that duty for the correct day.

    (I'm not sure if a ListBox instead of a ComboBox would be better either?!)

    Sorry if I haven't explained this clearly, however the attached file should help!

    Any help on this matter would be great, thanks!

    SA-Test.zip

  2. #2
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,455
    Location
    Private Sub CommandButton1_Click()
    Dim dutyNumber As String
    Dim startRow As Long
    Dim i As Long
    
        With Worksheets("SA Data")
        
           dutyNumber = Me.ListBox1.Value
            startRow = .Columns("E").Find(dutyNumber).Row
            Do While .Cells(startRow + i, "E").Value = dutyNumber
            
                Select Case .Cells(startRow + i, "B").Value
                
                    Case "Sun": .Cells(startRow + i, "K").Value = Me.Sunday.Text
                    Case "Mon": .Cells(startRow + i, "K").Value = Me.Monday.Text
                    Case "Tue": .Cells(startRow + i, "K").Value = Me.Tuesday.Text
                    Case "Wed": .Cells(startRow + i, "K").Value = Me.Wednesday.Text
                    Case "Thu": .Cells(startRow + i, "K").Value = Me.Thursday.Text
                    Case "Fri": .Cells(startRow + i, "K").Value = Me.Friday.Text
                    Case "Sat": .Cells(startRow + i, "K").Value = Me.Saturday.Text
                End Select
                
                i = i + 1
            Loop
        End With
    End Sub
    ____________________________________________
    Nihil simul inventum est et perfectum

    Abusus non tollit usum

    Last night I dreamed of a small consolation enjoyed only by the blind: Nobody knows the trouble I've not seen!
    James Thurber

  3. #3
    VBAX Newbie
    Joined
    Nov 2013
    Posts
    4
    Location
    Thats ideal, thanks so much!

    Would it be easy to clear the data from the textbox's if the duty was changed?

    *Edit - I've done the clearing thing.

    Again, thanks alot!
    Last edited by jsneak; 11-18-2013 at 12:07 PM.

Posting Permissions

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