Forum Discussion
DHitchcock
Jul 18, 2025Copper Contributor
Excel form - may need VBA?
Hi all, New to this forum, but here goes: Have a complex Excel workbook (on Sharepoint). We need a better way to do data entry but with certain restrictions Want the data entry form to default to...
Kidd_Ip
Jul 19, 2025MVP
Take this:
1. Default to Current Date in Entry Form
To automatically populate a textbox with today’s date when the form opens:
Private Sub UserForm_Initialize()
Me.txtDate.Value = Format(Date, "dd/mm/yyyy") ' Or use Now() for date + time
End Sub
- Replace txtDate with the name of your date textbox.
- This runs when the form loads and sets the default value.
2. Pull-Down Restrictions from Master Sheet
If your restrictions (e.g. dropdown options) are stored on a separate tab, you can populate a ComboBox like this:
Private Sub UserForm_Initialize()
Dim ws As Worksheet
Dim rng As Range
Dim cell As Range
Set ws = ThisWorkbook.Sheets("RestrictionsTab") ' Change to your tab name
Set rng = ws.Range("A2:A10") ' Change to your actual range
For Each cell In rng
Me.cboOptions.AddItem cell.Value
Next cell
End Sub
- cboOptions is your ComboBox name.
- This ensures the form reflects the latest restrictions from your master sheet.
3. Calculations Within the Form
To calculate values like Ending Number = Starting Number + Quantity dynamically:
Private Sub txtQuantity_Change()
If IsNumeric(Me.txtStart.Value) And IsNumeric(Me.txtQuantity.Value) Then
Me.txtEnd.Value = Val(Me.txtStart.Value) + Val(Me.txtQuantity.Value)
End If
End Sub
- This updates txtEnd automatically when txtQuantity changes.
- You can also trigger this on txtStart_Change if needed.
4. Saving Only Start and End to Database
When the user clicks a “Submit” button, you can write only the relevant fields to your database sheet:
Private Sub btnSubmit_Click()
Dim ws As Worksheet
Dim nextRow As Long
Set ws = ThisWorkbook.Sheets("DatabaseSheet") ' Change to your sheet name
nextRow = ws.Cells(ws.Rows.Count, "A").End(xlUp).Row + 1
ws.Cells(nextRow, 1).Value = Me.txtDate.Value
ws.Cells(nextRow, 2).Value = Me.txtStart.Value
ws.Cells(nextRow, 3).Value = Me.txtEnd.Value
End Sub