Solved

Activate Range in Worksheet Loop

Posted on 2011-03-23
2
400 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
Comment Utility
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
Comment Utility
This is perfect. Thank you!
0

Featured Post

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

How to quickly and accurately populate Word documents with Excel data, charts and images (including Automated Bookmark generation) David Miller (dlmille) Synopsis In this article you’ll learn how to use ExcelToWord! to copy data,charts, shapes …
This code takes an Excel list of URL’s and adds a header titled “URL List”. It then searches through all URL’s in column “A”, looking for duplicates. When a duplicate is found, it is moved to the top of the list. The duplicate URL’s are then highlig…
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.

743 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

15 Experts available now in Live!

Get 1:1 Help Now