Solved

Activate Range in Worksheet Loop

Posted on 2011-03-23
2
401 Views
Last Modified: 2012-05-11
I have a macro that loops through multiple worksheets and filters a row based on a user selection. When it gets to the second worksheet, it throws the error "Select method of Range Class Failed."

I think this might be because the second sheet is active but it's trying to select the range on the first sheet, but i don't know what I'm doing wrong... can you help?

Sub FilterAllWorksheets()
        Dim FilterRange As Range
   


     Set FilterRange = Application.InputBox(Prompt:= _
      "Please select the Row to be Filtered", _
       Title:="Filter Range", Type:=8)
               If FilterRange Is Nothing Then
        Exit Sub

   Else


    On Error GoTo 0

 Dim i As Integer
        For i = 1 To Sheets.Count
        Sheets(i).Select
       
       
        FilterRange.Select
       
     With ActiveSheet
    Selection.AutoFilter
   
    End With

           

        Next i
          End If


 Sheets(1).Select

 ActiveWindow.View = xlNormalView
End Sub
0
Comment
Question by:dbadmin78
2 Comments
 
LVL 81

Accepted Solution

by:
zorvek (Kevin Jones) earned 500 total points
ID: 35200579
Try this:

    Dim i As Integer
   
    For i = 1 To Sheets.Count
        Sheets(i).Range(FilterRange.Address).AutoFilter
    Next i

Kevin
0
 

Author Closing Comment

by:dbadmin78
ID: 35200798
This is perfect. Thank you!
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction This Article briefly covers methods of calculating the NPV and IRR variants in Excel as well as the limitations in calculating and interpreting IRR results. Paraphrasing Richard Shockley, author of my favourite finance reference tex…
Freeze panes is an option within all variants of Excel to enable parts of a sheet to remain stationary when the cursor is in another part of the sheet. This is a very useful feature which is overlooked or under used.
The view will learn how to download and install SIMTOOLS and FORMLIST into Excel, how to use SIMTOOLS to generate a Monte Carlo simulation of 30 sales calls, and how to calculate the conditional probability based on the results of the Monte Carlo …
This Micro Tutorial will demonstrate in Microsoft Excel how to add style and sexy appeal to horizontal bar charts.

914 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now