Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Activate Range in Worksheet Loop

Posted on 2011-03-23
2
Medium Priority
?
410 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 81

Accepted Solution

by:
zorvek (Kevin Jones) earned 2000 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

Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

Question has a verified solution.

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

In Part II of this series, I will discuss how to identify all open instances of Excel and enumerate the workbooks, spreadsheets, and named ranges within each of those instances.
This article describes a serious pitfall that can happen when deleting shapes using VBA.
This Micro Tutorial will demonstrate the scrolling table in Microsoft Excel using the INDEX function.
Many functions in Excel can make decisions. The most simple of these is the IF function: it returns a value depending on whether a condition you describe is true or false. Once you get the hang of using the IF function, you will find it easier to us…

610 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