macro runs in debug but NOT when I 'run' it

rog54bert

New Member
Joined
Jul 28, 2011
Messages
8
Don't understand how macro can run in step mode but not when I run it:

Sub PrintAllSheets()
Dim wb As Workbook, sht As Object

For Each wb In Excel.Workbooks

For Each sht In wb.Sheets
sht.Activate
ActiveSheet.Range("$AU$14:$AU$144").AutoFilter Field:=1, Criteria1:="1.00"
sht.PrintOut

Next sht

Next wb
End Sub

Has anyone had this happen?
 

Excel Facts

Wildcard in VLOOKUP
Use =VLOOKUP("Apple*" to find apple, Apple, or applesauce
Adjusted for the Code BB stuff . . .

I've since narrowed this issue to be the line containing autofilter:

Code:
Sub PrintAllSheets()
Dim wb As Workbook, sht As Object
For Each wb In Excel.Workbooks
 
    For Each sht In wb.Sheets
        sht.Activate
        If Not ActiveSheet.AutoFilterMode Then ActiveSheet.Range("$AU$14:$AU$144").AutoFilter
        ActiveSheet.Range("$AU$14:$AU$144").AutoFilter 1, "1"
        sht.PrintOut
    Next sht
Next wb
End Sub

This runs when I 'step' through the code. However, when I run the macro I get "Autofilter method of Range class failed". By way of background -- every sheet in every workbook has an active filter in column AU, rows 14-144. The filter is there to hide rows with 0 totals. The column contains either a "1" (not zero row) or a "0" (zero row).
 
Upvote 0
I moved this project home and found out more. Is there any reason the above code would not run from personal.xlsb? The macro runs from within the object workbook but only if there is NO personal.xlsb file. If there is a personal.xlsb file (even with no macros), the above macro errors out. If I delete the personal.xlsb file and import the macro into object workbook the macro works. The problem is I have 22 files with varying numbers of sheets and would much rather run the macro remotely than from inside each file. Any help would be much appreciated.
 
Upvote 0

Forum statistics

Threads
1,224,558
Messages
6,179,512
Members
452,920
Latest member
jaspers

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