Code to click "OK" on message box

ExcelPupper

Board Regular
Joined
Mar 2, 2020
Messages
112
Office Version
  1. 2019
Platform
  1. Windows
Hi, I always encounter this prompt message every time I run my code below. Is there a code that automatically clicks "OK" once it appears? Btw, it appears twice because I made 2 subtotals for two different columns. Thanks!


1597300752123.png



VBA Code:
Sub Subtotal()
Dim Lastrow As Long

' Subtotal per Customer and Class

    Sheets(1).Activate
Lastrow = Range("A" & Rows.Count).End(xlUp).Row

Range("A1:N" & Lastrow).Select
Selection.Subtotal GroupBy:=2, Function:=xlSum, TotalList:=Array(6, 11, 12) _
, Replace:=False, PageBreaks:=False, SummaryBelowData:=True
Range("A1:N" & Lastrow + 5).Select
Range(Selection, Selection.End(xlDown)).Select
Selection.Subtotal GroupBy:=10, Function:=xlSum, TotalList:=Array(6, 11, 12 _
), Replace:=False, PageBreaks:=False, SummaryBelowData:=True


End Sub
 

Excel Facts

Excel Wisdom
Using a mouse in Excel is the work equivalent of wearing a lanyard when you first get to college
You can stop the message in the first place.
Put near the start of your code Application.DisplayAlerts = False
and near the end Application.DisplayAlerts = True
 
Upvote 0
You can stop the message in the first place.
Put near the start of your code Application.DisplayAlerts = False
and near the end Application.DisplayAlerts = True


Hi I've tried the code below:
VBA Code:
Sub Subtotal()
Applications.DisplayAlerts = False

Dim Lastrow As Long

' Subtotal per Customer and Class

    Sheets(1).Activate
Lastrow = Range("A" & Rows.Count).End(xlUp).Row

Range("A1:N" & Lastrow).Select
Selection.Subtotal GroupBy:=2, Function:=xlSum, TotalList:=Array(6, 11, 12) _
, Replace:=False, PageBreaks:=False, SummaryBelowData:=True
Range("A1:N" & Lastrow + 5).Select
Range(Selection, Selection.End(xlDown)).Select
Selection.Subtotal GroupBy:=10, Function:=xlSum, TotalList:=Array(6, 11, 12 _
), Replace:=False, PageBreaks:=False, SummaryBelowData:=True


Applications.DisplayAlerts = True

End Sub

But I get this error
1597372818803.png
 
Upvote 0
First of all you need to remove the s from Applications, it is
VBA Code:
Application.DisplayAlerts = True
not
Rich (BB code):
Applications.DisplayAlerts = True

You need to do it in both the True and False statements.
 
Upvote 0
First of all you need to remove the s from Applications, it is
VBA Code:
Application.DisplayAlerts = True
not
Rich (BB code):
Applications.DisplayAlerts = True

You need to do it in both the True and False statements.

Ohh okay thanks btw. I didn't notice that lol
 
Upvote 0
But I get this error
Just for the future, if you get a code error, as well as giving us the full error message (which you did (y)), also click the Debug button and tell us which line in the code is highlighted.
 
Upvote 0

Forum statistics

Threads
1,214,962
Messages
6,122,482
Members
449,088
Latest member
Melvetica

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