We help IT Professionals succeed at work.

Help with user form in Excel (combobox and linking entry to next available row in spreadsheet)

I have created a user form called Time Tracker, and been able to link the first combobox (called cboIDList) to the range called ID.

I am having difficulty with the next steps:
  • Autopopulating the combobox called cboPA_Unit, which is to be based on the value that users selects for cboIDList and references the range called PA_Unit.
  • Autopopulating the combobox called cboDesc, which is based on the value that users selects for cboIDList, and references the range called Description
  • Getting data of a completed user form to populate the next available row in a target spreadsheet

For example, if the user opens the user form and selects 2017-0001 in the dropdown for the ID combo box, then the PA Unit and Description combo boxes would both autopopulate with "Unit 1" and "Reduce Publication Files" respectively.

The txtDate field should already be autopopulated with the current date:
  • I would like users to be able to edit the date if necessary, in case they were away and need to back date a record.

Once the user completes the form by entering a value in the 'Minutes' text box, then I would like the data from the form to populate the next available row in the spreadsheet called TrackingSheet as follows:

TrackingSheet!Column A = reflects value entered in cboIDList
TrackingSheet!Column B = reflects value entered in cboPA_List
Tracking Sheet!Column C = reflects value entered in cboDesc
TrackingSheet!Column D = reflects value entered in txtDate
TrackingSheet!Column E = reflects value entered in txtMinutes

If the user form is not completely filled out, then no data should be entered into the TrackingSheet.

Description of my attached sample spreadsheet:

Dynamic named ranges:
ID = Tasks!Column A
PA_Unit = Tasks! Column B
Description = Tasks!Column C

I think I've covered it. I am new at user forms, so if you feel there are glaring issues or error handling that I should add, it would be very helpful to know.

I have attached a sample spreadsheet with my user form completed thus far, as described above.
Watch Question

Analyst Assistant
The first part is easy, Though I'm not quite sure why you are using comboboxes when there aren't multiple values.

Private Sub cboIDList_Change()
Dim idx As Long

    With Me
        idx = .cboIDList.ListIndex
        If idx <> -1 Then
            .cboDesc.Value = Sheets("Tasks").Range("C" & idx + 2).Value
            .cboPA_Unit.Value = Sheets("Tasks").Range("B" & idx + 2).Value
        End If

    End With
End Sub

Open in new window

For the data part, you are already populating a textbox with the current date and the user can easily change that if they want.

As for transferring the data from the userform to the sheet 'TrackingSheet', you could use this code,
Dim NextRow As Long

    With Me
        If .cboIDList.Value = "" _
            Or .cboDesc.Value = "" _
            Or .cboPA_Unit.Value = "" _
            Or .txtDate = "" _
            Or txtMinutes = "" Then
            MsgBox "Form not completed!", vbCritical, "Incomplete"
            Exit Sub
        End If

        NextRow = Sheets("TrackingSheet").Range("A" & Rows.Count).End(xlUp).Row + 1
        Sheets("TrackingSheet").Range("A" & NextRow).Value = .cboIDList.Value
        Sheets("TrackingSheet").Range("B" & NextRow).Value = .cboPA_Unit.Value
        Sheets("TrackingSheet").Range("C" & NextRow).Value = .cboDesc.Value
        Sheets("TrackingSheet").Range("D" & NextRow).Value = .txtDate.Value
        Sheets("TrackingSheet").Range("E" & NextRow).Value = .txtMinutes.Value
    End With

Open in new window

which I've put in the Click event of the command button cmdSave I've added to the userform in the attached file.


Terrific - thanks very much, Norie!

I will change the combo boxes, since they aren't necessary, as you mentioned. The one thing I realized as I tested is that I should have included the clearing of the form of data after clicking the 'Save' button as part of the criteria. I'll see if I can figure that out. :-)



Thanks for the quick response...