erutherford
Active Member
- Joined
- Dec 19, 2016
- Messages
- 449
Spent a lot of time and haven't found the solution. I have a good working form and a good working macro. I need the macro to run when the "submit" button is selected in the form. Answer is probably looking right at me, but I am not seeing it. I tried "Call" function etc. Has to be a simple, but I could use the help.
Thanks
Form code
Macro code
Thanks
Form code
Code:
Private Sub CommandButton1_Click() 'Submit ufCars
Dim lRow As Long
Dim lActivity As Long
Dim ws As Worksheet
Set ws = Worksheets("MyCars")
'find first empty row in database
lRow = ws.Cells.Find(What:="*", SearchOrder:=xlRows, _
SearchDirection:=xlPrevious, LookIn:=xlValues).Row + 1
'check Years
If Trim(Me.cbxYear.Value) = "" Then
cbxYear.SetFocus
MsgBox "Please select a Year. Required Field"
Exit Sub
End If
'check License Plate
If Trim(Me.tbxLicense.Value) = "" Then
tbxLicense.SetFocus
MsgBox "Please enter License Plate Info. Required Field"
Exit Sub
End If
'use protect and unprotect lines,
' with your password
' if worksheet is protected
With ws
' .Unprotect Password:="password"
.Cells(lRow, 1).Value = Me.cbxYear.Value
.Cells(lRow, 2).Value = Me.tbxMake.Value
.Cells(lRow, 3).Value = Me.tbxModel.Value
.Cells(lRow, 5).Value = Me.tbxLicense.Value
.Cells(lRow, 6).Value = Me.tbxColor.Value
.Cells(lRow, 7).Value = Me.tbxVIN.Value
.Cells(lRow, 8).Value = Me.tbxPDate.Value
.Cells(lRow, 9).Value = Me.tbxPAmt.Value
.Cells(lRow, 10).Value = Me.tbxPMiles.Value
.Cells(lRow, 11).Value = Me.tbxInsurDate.Value
.Cells(lRow, 12).Value = Me.tbxRegDate.Value
' .Protect Password:="password"
End With
'clear the data after entry
Me.cbxYear.Value = ""
Me.tbxMake.Value = ""
Me.tbxModel.Value = ""
Me.tbxLicense.Value = ""
Me.tbxColor.Value = ""
Me.tbxVIN.Value = ""
Me.tbxPDate.Value = ""
Me.tbxPAmt.Value = ""
Me.tbxPMiles.Value = ""
Me.tbxInsurDate.Value = ""
Me.tbxRegDate.Value = ""
End Sub
Macro code
Code:
Sub MyCarsCombined()
Dim lngLastRow As Long
'Uses Column A to set the 'lngLastRow' variable _
(find the last row) - change if required.
lngLastRow = Cells(Rows.Count, "A").End(xlUp).Row
Range("D2:D" & lngLastRow).Value = Evaluate("=A2:A" & lngLastRow & "&"" ""&" & "B2:B" & lngLastRow & "&"" ""&" & "E2:E" & lngLastRow)
End Sub