Solved

Activate Range in Worksheet Loop

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

Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

Question has a verified solution.

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

Suggested Solutions

Convert between Excel file formats (.XLS, .XLSX, .XLSM) with/without macro option David Miller (dlmille) Intro Over this past Fall, I've had the opportunity to see several similar requests and have developed a couple related solutions associate…
Some code to ensure data integrity when using macros within Excel. Also included code that helps secure your data within an Excel workbook.
The viewer will learn how to use the =DISCRINV command to create a discrete random variable, use this command to model a set of probabilities and outcomes in a Monte Carlo simulation, and learn how to find the standard deviation of a set of probabil…
This Micro Tutorial demonstrates using Microsoft Excel pivot tables, how to reverse engineer competitors' marketing strategies through backlinks.

786 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