View Single Post
  #1   Report Post  
Posted to microsoft.public.excel.programming
[email protected] menken.john@gmail.com is offline
external usenet poster
 
Posts: 14
Default Weird ignoring of one item in a loop

Hi, I'm using Excel 2010 on Windows 7 and I have created a loop that goes through each worksheet in the workbook and performs several routine operations. For some strange reason it ignores my line about turning off the autofilter. When I run the macro it resets the cursor to A1 and eliminates any marching ants but the AutoFilter on several sheets remains 'on.' Can anyone tell me what I might be doing wrong? I've included the code below. Many thanks.

Code:
'Reset the cursor to cell A1 on all sheets, turn any autofilters off
'and lose any marching ants that might remain

    Dim i As Integer

    For i = 1 To Sheets.Count
        With Worksheets(i)
            
            Range("A1").Select
            If ActiveSheet.AutoFilterMode = True Then ActiveSheet.AutoFilterMode = False
            Application.CutCopyMode = False   'This gets rid of any marching ants that may remain
           
        End With
    Next i