erutherford
Active Member
- Joined
- Dec 19, 2016
- Messages
- 449
I have a form that enters data in Col A, B, C.
A macro runs next that groups the data into Col D
Here is the macro ( runs fine manually)
But when I call for the macro in the sub it won't run. I have tried moving it in a number of places, but no luck. Manually fine
here is where I call for it
ideas????
A macro runs next that groups the data into Col D
Here is the macro ( runs fine manually)
Code:
Sub MyCarsCombined()
Dim lngLastRow As Long
Application.ScreenUpdating = False
'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)
Application.ScreenUpdating = True
End Sub
But when I call for the macro in the sub it won't run. I have tried moving it in a number of places, but no luck. Manually fine
here is where I call for it
Code:
Private Sub CommandButton3_Click() 'Submit ufCars
Dim answer As Integer
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"
cbxYear.BackColor = vbYellow
Exit Sub
End If
'check Make
If Trim(Me.tbxMake.Value) = "" Then
tbxMake.SetFocus
MsgBox "Please enter Make of the Car. Required Field"
tbxMake.BackColor = vbYellow
Exit Sub
End If
'check License Plate
If Trim(Me.tbxLicense.Value) = "" Then
tbxLicense.SetFocus
MsgBox "Please enter License Plate Info. Required Field"
tbxLicense.BackColor = vbYellow
Exit Sub
End If
If cbxYear.BackColor = vbYellow Then
cbxYear.BackColor = vbWhite
End If
If tbxMake.BackColor = vbYellow Then
tbxMake.BackColor = vbWhite
End If
If tbxLicense.BackColor = vbYellow Then
tbxLicense.BackColor = vbWhite
End If
'use protect and unprotect lines,
' with your password
' if worksheet is protected
With ws
.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
End With
Call MyCarsCombined ' Macro
'clears 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 = ""
answer = MsgBox("Want to add another car?", vbQuestion + vbYesNo + vbDefaultButton2, "Add another Car")
If answer = vbYes Then
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 = ""
Else
Unload ufAddCar
Call Dashboard_Open
End If
Call MyCarsCombined ' Macro
End Sub
ideas????