Error Handler not handling error...

D

Daniel Bonallack

I have code that loops through a workbook, copies the
contents of each sheet and pastes it to another workbook.

For each sheet I have this line:
ActiveSheet.ShowAllData

Most of the sheets are not filtered, so at this line the
code jumps into the error handler, where "Resume Next" is
waiting to push it back up into the loop.

The problem is this:
On the eighth sheet without filters, I get a debug error
on the ShowAllData line - it's like the errors are
stacking up. Can someone tell me what's happening, and
how to avoid this problem?

Thanks in advance.
Daniel
 
D

Dave Peterson

Maybe this will solve your immediate problem:

Option Explicit
Sub testme()

Dim wks As Worksheet

For Each wks In ActiveWorkbook.Worksheets
With wks
If .AutoFilterMode Then
If .FilterMode Then
.ShowAllData
End If
End If
End With
Next wks
End Sub

I'm not sure what's causing your other error, though.
 
B

BrianB

I tried to reproduce this and the code works OK.

It is more likely that you have a different error occurring with sheet
8 which is being trapped (been there, done that). Comment out the On
Error .. line to see the error message.

Regards
BrianB
===========================================
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top