Reputation: 29
When I use the AutoSUM the sub exits and I need to hit the Enter Key manually. I tried to hard code the Enter Key but once the code gets to the Application.CommandBars... the code still exits the sub.
Thank you all in advance.
I have the following code:
For r = fRows + 1 To ActiveSheet.UsedRange.Rows.count
If Cells(r, 3).Value <> Cells(r + 1, 3).Value And Not Cells(r, 3).Value = 0 Then
Cells(r + 1, 12).Select
Application.CommandBars("Standard").Controls("Autosum").Controls("Sum").Execute.SendKeys "{ENTER}"
Application.SendKeys "{ENTER}"
End If
Next r
Upvotes: 0
Views: 107
Reputation: 769
TBH, I never used something like SendKeys
in a VBA Macro. You should rather use something like
Cells(r + 1, 12).FormulaR1C1 = "=SUM(R1C12:R" & r & "C12)"
or
Cells(r + 1, 12).Formula = "=SUM(L1:L" & r & ")"
Your original question why the AutoSum command is not working I cannot answer.
Upvotes: 1