Calling a Macro pretty simple yet...

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)

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????
 

Excel Facts

Why does 9 mean SUM in SUBTOTAL?
It is because Sum is the 9th alphabetically in Average, Count, CountA, Max, Min, Product, StDev.S, StDev.P, Sum, VAR.S, VAR.P.
Same results - Macro won't run when form is called from the dashboard
Set a breakpoint and see if it hits when you click the button and change application.screenupdating lines to comments, or add a debug.print line
 
Upvote 0
That completely jumbled the data, started on row 2, erased all data col.D and added the word "today" on row 2 Col D. I'll set up your code in a clean workbook and test there before we try something else.
 
Upvote 0
The code in userform should be attached to the UserForm.
 
Upvote 0
I have been flying by the seat of my pants writing this. So when I created the form and started writing the code for it. I just selected the form and the vb editor open up and I started writing. None of this is in a Module. Just the macro.
 
Upvote 0
ok i put your code in a new workbook and your macro code worked fine. I created a new worksheet with a cmd button to open the form and that's where the problem starts. Same symptoms.

So I'll stay in this simple workbook for now. So I want a dashboard so I can open the forms. What is the proper way/method for doing that?.
 
Upvote 0

Forum statistics

Threads
1,216,119
Messages
6,128,944
Members
449,480
Latest member
yesitisasport

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top