Error 1004 - this can't be applied to selected range

paulr1680

New Member
Joined
Dec 11, 2019
Messages
2
Office Version
  1. 365
  2. 2016
  3. 2010
Following code is used to set up subtotals:-

Range("A1").Select
rowcount = Selection.CurrentRegion.Rows.Count
colcount = Selection.CurrentRegion.Columns.Count
Range(Range("A1"), Range("A1").Offset(0, colcount - 1)).Select
Selection.Subtotal GroupBy:=1, Function:=xlSum, TotalList:=Array(8, 9), Replace:=True, PageBreaks:=False, SummaryBelowData:=True

This sometimes, but not always, fails "Error 1004: This can't be applied to the selected range. Select a single cell in a range and try again"

If a single cell is selected, current region is assumed, so I commented out the "Range(Range("A1"), Range("A1").Offset(0, colcount - 1)).Select" line

In this case one test that had previously failed now worked; however another test still failed.

Any suggestions?
Is the intermittent failure because of the amount of data?

Thanks in anticipation

Paul
 

Excel Facts

What do {} around a formula in the formula bar mean?
{Formula} means the formula was entered using Ctrl+Shift+Enter signifying an old-style array formula.
You're applying subtotals to the 8th and 9th columns in the selection / region as dictated by TotalList:=Array(8, 9)
The number of columns in the selection / region can not be less that the highest number in the array.
 
Upvote 0
You're applying subtotals to the 8th and 9th columns in the selection / region as dictated by TotalList:=Array(8, 9)
The number of columns in the selection / region can not be less that the highest number in the array.
Thanks Jason, but I'm afraid that isn't the problem - the region extends to column 46
Paul
 
Upvote 0
There is nothing else there that would cause an error unless the sheet is protected.

What does
VBA Code:
MsgBox Range("A1").CurrentRegion.Address(0, 0)
tell you?
 
Upvote 0

Forum statistics

Threads
1,214,918
Messages
6,122,257
Members
449,075
Latest member
staticfluids

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