+ Reply to Thread
Results 1 to 4 of 4

Object Variable or with block variable not set - Autofilter

  1. #1
    Registered User
    Join Date
    06-25-2020
    Location
    India
    MS-Off Ver
    Office 365
    Posts
    11

    Object Variable or with block variable not set - Autofilter

    Hi, I am running a macro in a system since very long, but suddenly the same file is throwing me error at specific line when I run the file in a new laptop. Appereciate any help here (Error is with "Set RangeFilter = ActiveSheet.AutoFilter.Range"). Below is part of the code for any reviews.

    Sub CashAccounts()

    Dim MonthTab As String
    Dim RangeFilter As Range
    Dim R As Long, F As Long

    Sheets("Input").Select
    MonthTab = Range("B2").Value

    If Range("A7").Value = "" Then
    MsgBox "There is no data to add", vbInformation, "No Data"
    Range("A7").Select
    Exit Sub
    End If

    Application.ScreenUpdating = False
    Sheets(MonthTab).Select
    Set RangeFilter = ActiveSheet.AutoFilter.Range
    R = RangeFilter.Rows.Count
    F = RangeFilter.SpecialCells(xlCellTypeVisible).Rows.Count

  2. #2
    Forum Expert JLGWhiz's Avatar
    Join Date
    02-20-2011
    Location
    Florida, USA
    MS-Off Ver
    Windows 10, Excel 2013
    Posts
    2,070

    Re: Object Variable or with block variable not set - Autofilter

    If your filter is not activated you cannot use AutoFilter.Range to set a variable.
    Activate the filter first and then set the variable. The range will be the same as the total area of data which was used to filter, not just the filtered items.
    Last edited by JLGWhiz; 06-25-2020 at 01:47 PM.
    Any code provided by me should be tested on a copy or a mock up of your original data before applying it to the original. Some events in VBA cannot be reversed with the undo facility in Excel. If your original post is satisfied, please mark the thread as "Solved". To upload a file, see the banner at top of this page.
    Just when I think I am smart, I learn something new!

  3. #3
    Registered User
    Join Date
    06-25-2020
    Location
    India
    MS-Off Ver
    Office 365
    Posts
    11

    Thumbs up Re: Object Variable or with block variable not set - Autofilter

    Awesome, Thank you, I was missing this simple solution. Thanks for your time.

  4. #4
    Forum Expert JLGWhiz's Avatar
    Join Date
    02-20-2011
    Location
    Florida, USA
    MS-Off Ver
    Windows 10, Excel 2013
    Posts
    2,070

    Re: Object Variable or with block variable not set - Autofilter

    Quote Originally Posted by sai.krishnaa2006 View Post
    Awesome, Thank you, I was missing this simple solution. Thanks for your time.
    You're welcome, Don't forget to mark the thread as Solved (Thread Tools button at top of page)
    Regards, JLG

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Replies: 12
    Last Post: 12-28-2019, 12:29 PM
  2. [SOLVED] Run-time error '91': Object variable or With block variable not set when closing userform
    By bishoposiris in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 02-10-2016, 08:59 AM
  3. Advanced Excel - Object variable or With block variable not set (Error 91)??
    By larryg003 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 12-19-2014, 01:37 PM
  4. Replies: 2
    Last Post: 08-22-2014, 03:55 AM
  5. Macro issue: Object variable or with block variable not set error
    By utgjmb1 in forum Excel Programming / VBA / Macros
    Replies: 8
    Last Post: 07-29-2013, 06:07 AM
  6. Replies: 4
    Last Post: 07-12-2013, 12:14 PM
  7. Replies: 6
    Last Post: 12-21-2012, 08:03 AM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1