Solved

Activate Range in Worksheet Loop

Posted on 2011-03-23
2
406 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 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

Salesforce Made Easy to Use

On-screen guidance at the moment of need enables you & your employees to focus on the core, you can now boost your adoption rates swiftly and simply with one easy tool.

Question has a verified solution.

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

This tutorial explains how to create a series of drop-down lists that are dependent upon prior selections to guide (“force”) the user to make the correct selection and reduce data errors within Microsoft Excel. Excel 2010 was used for this tutorial;…
This article describes a serious pitfall that can happen when deleting shapes using VBA.
The viewer will learn how to create two correlated normally distributed random variables in Excel, use a normal distribution to simulate the return on different levels of investment in each of the two funds over a period of ten years, and, create a …
This Micro Tutorial will demonstrate in Microsoft Excel how to add style and sexy appeal to horizontal bar charts.

726 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