PDA

View Full Version : Filling Cells with a TextBox matching a ComboBox - VBA Code



jsneak
11-18-2013, 09:44 AM
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 :rofl:

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!

10843

Bob Phillips
11-18-2013, 11:30 AM
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

jsneak
11-18-2013, 11:33 AM
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!