+ Reply to Thread
Results 1 to 3 of 3

Thread: Avoiding Error 1004

  1. #1
    Registered User
    Join Date
    05-27-2011
    Location
    Ontario, Canada
    MS-Off Ver
    Excel 2007
    Posts
    72

    Avoiding Error 1004

    I have code to trigger a macro once a specific cell is changed, the macro triggers this code:

    Sub FilterLog()
    Range("Data_Log").AdvancedFilter Action:=xlFilterCopy, copytorange:=Range("DataOut"), criteriarange:=Range("Criteria")
    End Sub
    If there is not at least 2 rows of data in the "Data_Log" range then I get Error 1004. Is there any form of "if" statement I can add to the line of code above to trigger a MsgBox instead of that error?
    Last edited by nohero; 06-30-2011 at 02:54 PM.

  2. #2
    Valued Forum Contributor tigeravatar's Avatar
    Join Date
    03-25-2011
    Location
    USA
    MS-Off Ver
    Excel 2003 - 2007
    Posts
    2,352

    Re: Avoiding Error 1004

    nohero,

    Something like this?
    Sub FilterLog()
        If Range("Data_Log").Rows.Count < 2 Then
            MsgBox "The range ""Data_Log"" contains less than 2 rows"
        Else
            Range("Data_Log").AdvancedFilter Action:=xlFilterCopy, copytorange:=Range("DataOut"), criteriarange:=Range("Criteria")
        End If
    End Sub


    Hope that helps,
    ~tigeravatar

  3. #3
    Registered User
    Join Date
    05-27-2011
    Location
    Ontario, Canada
    MS-Off Ver
    Excel 2007
    Posts
    72

    Re: Avoiding Error 1004

    Works like a charm, first try. I really wish the forum allowed me to give you back to back +rep since it was 2 separate issues you just helped me with.

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

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.2.0