View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.programming
Dave Peterson Dave Peterson is offline
external usenet poster
 
Posts: 35,218
Default macro to continue running if error

I'd try...

Option Explicit
Sub UpdateAll()
Dim iCtr As Long
Dim myArr As Variant
Dim TestWks As Worksheet

myArr = Array("1", "2", "3", "4", "5", "6", "7", _
"10", "11", "12", "21", "22", _
"23", "24", "25", "26", "27", _
"28", "29", "30", "31", "41", "42", _
"43", "44", "45", "46", _
"47", "48", "49", "50", "51", "52", _
"53", "54", "55", "61")

For iCtr = LBound(myArr) To UBound(myArr)
Set TestWks = Nothing
On Error Resume Next
Set TestWks = Worksheets(myArr(iCtr))
On Error GoTo 0

If TestWks Is Nothing Then
'not found!
Else
TestWks.Select
Call macFilter
End If
Next iCtr

End Sub

I wouldn't use Filter as the name of a procedure. If you search VBA's help,
you'll see that it's used by excel.

Norvascom wrote:

Hi,

I have the following macro that is working fine. It is looking at a
specified worksheet array and executing the macro "Filter" on each
worksheets. However, in case one of the worksheet is not existing, I
would like the macro to pass the non existing worksheet and continue
running on the next available worksheet. I tried adding the following
statement: "On Error Resume Next" at the beginning but it is passing
everything.

Any help would be appreciated.
Thanks

Sub UpdateAll()
For Each sh In Worksheets(Array("1", "2", "3", "4", "5", "6", "7",
"10", "11", "12", "21", "22", _
"23", "24", "25", "26", "27", "28", "29", "30", "31", "41", "42",
"43", "44", "45", "46", _
"47", "48", "49", "50", "51", "52", "53", "54", "55", "61"))
sh.Select
Call Filter
Next sh
End Sub


--

Dave Peterson