my vba code isnt working

bigdan

Well-known Member
Joined
Oct 5, 2009
Messages
843
Office Version
  1. 2013
Platform
  1. Windows
I'm new to VBA so this is probably an elementary mistake. I created this code by recording my actions.

Essentially I want to be able to double-click on a cell in a pivot table to see what's going on there. I'll do that manually. That'll then open up a dataset which has 43 columns. The number of rows vary, they could be 3 they could be 7800.

So anyway when there's 43 columns I want to hide the irrelevant stuff. I generated this code to do just that. But it's not working when I doubleclick on a different cell in the pivot. I'm guessing it's objecting to the number of rows but am not sure. I'd assume the columns are the exact same.

The error is: Run-time error 1004. Select method of range class failed.


Here's the code.

Sub Grouping()
'
' Grouping Macro

Columns("A:E").Select
Selection.Columns.Group
Columns("G:I").Select
Selection.Columns.Group
Columns("K:O").Select
Selection.Columns.Group
Columns("Q:AC").Select
Selection.Columns.Group
Columns("AG:AQ").Select
Selection.Columns.Group
Range("Table1[[#Headers],[ACCOUNT_NO]]").Select
End Sub
 

Excel Facts

Which lookup functions find a value equal or greater than the lookup value?
MATCH uses -1 to find larger value (lookup table must be sorted ZA). XLOOKUP uses 1 to find values greater and does not need to be sorted.
Try referencing the sheet name, as in
Sheets("Sheet1").Range("Table1[[#Headers],[ACCOUNT_NO]]").Select
 
Upvote 0
I'm afraid that didn't work. I got the exact same error message. But I noticed that although I got an error, the grouping was done properly. And then realized the line that's giving a problem is at the end of the code. So I've just commented that out and yeah that seems to work!

That said, why is that line giving an objection?
 
Upvote 0
Sorry, no idea other than to guess it doesn't like something about the syntax of the range reference.
 
Upvote 0

Forum statistics

Threads
1,215,758
Messages
6,126,718
Members
449,332
Latest member
nokoloina

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