Subtotal in macro does not know labels are in first row

General Ledger

Active Member
Joined
Dec 31, 2007
Messages
460
Dear All,

When I run this code,

Code:
Rows("1:1").NumberFormat = "@"
 
Cells.Subtotal GroupBy:=1, Function:=xlSum, TotalList:=Array(18, 19, 20), _
 Replace:=True, PageBreaks:= False, SummaryBelowData:=True

I get an error:

Microsoft Excel cannot determine which row in your list or selection contains column labels, which are required for this command.

I select OK for the option:

If you want the first row of the selection or list used as labels and not as data, click OK

The result is exactly as I want. Of course I would rather the user not have to tell Excel the first row contains the lables.

Here are cells A1:C2 to illustrate I have text in the first row:

<TABLE style="WIDTH: 294pt; BORDER-COLLAPSE: collapse" border=0 cellSpacing=0 cellPadding=0 width=392><COLGROUP><COL style="WIDTH: 146pt; mso-width-source: userset; mso-width-alt: 7131" width=195><COL style="WIDTH: 72pt; mso-width-source: userset; mso-width-alt: 3510" width=96><COL style="WIDTH: 76pt; mso-width-source: userset; mso-width-alt: 3693" width=101><TBODY><TR style="HEIGHT: 12.75pt" height=17><TD style="BORDER-BOTTOM: #f0f0f0; BORDER-LEFT: #f0f0f0; BACKGROUND-COLOR: transparent; WIDTH: 146pt; HEIGHT: 12.75pt; BORDER-TOP: #f0f0f0; BORDER-RIGHT: #f0f0f0" height=17 width=195>Customer Name</TD><TD style="BORDER-BOTTOM: #f0f0f0; BORDER-LEFT: #f0f0f0; BACKGROUND-COLOR: transparent; WIDTH: 72pt; BORDER-TOP: #f0f0f0; BORDER-RIGHT: #f0f0f0" width=96>Invoice</TD><TD style="BORDER-BOTTOM: #f0f0f0; BORDER-LEFT: #f0f0f0; BACKGROUND-COLOR: transparent; WIDTH: 76pt; BORDER-TOP: #f0f0f0; BORDER-RIGHT: #f0f0f0" width=101>Advance/Invoice</TD></TR><TR style="HEIGHT: 12.75pt" height=17><TD style="BORDER-BOTTOM: #f0f0f0; BORDER-LEFT: #f0f0f0; BACKGROUND-COLOR: transparent; HEIGHT: 12.75pt; BORDER-TOP: #f0f0f0; BORDER-RIGHT: #f0f0f0" height=17>ABC COMPANY INC</TD><TD style="BORDER-BOTTOM: #f0f0f0; BORDER-LEFT: #f0f0f0; BACKGROUND-COLOR: transparent; BORDER-TOP: #f0f0f0; BORDER-RIGHT: #f0f0f0">1004120866</TD><TD style="BORDER-BOTTOM: #f0f0f0; BORDER-LEFT: #f0f0f0; BACKGROUND-COLOR: transparent; BORDER-TOP: #f0f0f0; BORDER-RIGHT: #f0f0f0">Invoice</TD></TR></TBODY></TABLE>

When I use the macro recorder and execute the Subtotal feature on the same data, it does not ask me for the row of my labels.

According to the VBA Help, the syntax does not ask for the row of the labels.

Code:
[B][I]expression[/I].Subtotal([I]GroupBy[/I], [I]Function[/I], [I]TotalList[/I], [I]Replace[/I],  _[/B]
[B][I]PageBreaks[/I], [I]SummaryBelowData[/I])[/B]

Why doesn't Excel know my first row has labels?

How can I tell the Subtotal function the labels are in the first row, or have the macro respond OK to the error?

Any ideas?

Thanks,

GL
 

Excel Facts

Which came first: VisiCalc or Lotus 1-2-3?
Dan Bricklin and Bob Frankston debuted VisiCalc in 1979 as a Visible Calculator. Lotus 1-2-3 debuted in the early 1980's, from Mitch Kapor.
See if this works

Code:
Application.DisplayAlerts = False
Cells.Subtotal GroupBy:=1, Function:=xlSum, TotalList:=Array(18, 19, 20), _
 Replace:=True, PageBreaks:=False, SummaryBelowData:=True
Application.DisplayAlerts = True
 
Upvote 0
VoG,

Once again you have the solution.

So I might learn, what is the logic and purpose behind the code:
Code:
Application.DisplayAlerts = False

Is this a line of code that most every macro should include at the beginning?

Thanks,

GL
 
Upvote 0
Is this a line of code that most every macro should include at the beginning?


No, definitely not! Only use it where you want to suppress an anticipated message. It is commonly used before deleting sheets for example to avoid the standard Excel warning.
 
Upvote 0

Forum statistics

Threads
1,224,540
Messages
6,179,417
Members
452,912
Latest member
alicemil

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