+ Reply to Thread
Results 1 to 10 of 10

Application error or object-defined error

  1. #1
    Forum Contributor
    Join Date
    09-19-2017
    Location
    London
    MS-Off Ver
    2015
    Posts
    169

    Question Application error or object-defined error

    Hi, all

    I previously ran this code and it worked well. But suddenly this application error or object-defined error came out of nowhere.

    Please Login or Register  to view this content.
    Here's the highlighted part of it:
    Please Login or Register  to view this content.
    I have no idea why. Mind to explain?

  2. #2
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,644

    Re: Application error or object-defined error

    Any chance you could upload a sample workbook?

    Click on GO ADVANCED, scroll down and click Manage Attachments.
    If posting code please use code tags, see here.

  3. #3
    Forum Contributor
    Join Date
    09-19-2017
    Location
    London
    MS-Off Ver
    2015
    Posts
    169

    Re: Application error or object-defined error

    Quote Originally Posted by Norie View Post
    Any chance you could upload a sample workbook?
    I can upload a sample, but turns out it works well on my sample workbook but not my actual workbook

    What should I do now?

  4. #4
    Forum Expert leelnich's Avatar
    Join Date
    03-20-2017
    Location
    Delaware, USA
    MS-Off Ver
    Office 2016
    Posts
    2,807

    Re: Application error or object-defined error

    Hi ell - You're using the SpecialCells(xlCellTypeVisible) method to find visible cells within a specified range. If none are found, it generates an error, which happens when there are no rows that meet your filter criteria. Make sure you're referencing the correct range, and that it has some visible cells.
    Last edited by leelnich; 02-04-2018 at 08:27 PM.
    Clicking the Add Reputation star below helpful posts is a great way to show your appreciation.
    Please mark your threads as SOLVED upon conclusion (Thread Tools above Post # 1). - Lee

  5. #5
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,644

    Re: Application error or object-defined error

    What happens with this code?
    Please Login or Register  to view this content.

  6. #6
    Forum Contributor
    Join Date
    09-19-2017
    Location
    London
    MS-Off Ver
    2015
    Posts
    169

    Re: Application error or object-defined error

    Hi, Leelnich. What should I replace instead to make the code works?

    Norie, the code actually filters the DTE_Raw to only show data which similar to data in cell K2 and M2, then it copies to sheet DTE
    Last edited by ell_; 02-04-2018 at 08:33 PM.

  7. #7
    Forum Expert leelnich's Avatar
    Join Date
    03-20-2017
    Location
    Delaware, USA
    MS-Off Ver
    Office 2016
    Posts
    2,807

    Re: Application error or object-defined error

    This will skip the copy if there are no cells found:
    Please Login or Register  to view this content.
    MATCHES should be Dim'ed As Range
    Last edited by leelnich; 02-04-2018 at 08:37 PM.

  8. #8
    Forum Contributor
    Join Date
    09-19-2017
    Location
    London
    MS-Off Ver
    2015
    Posts
    169

    Re: Application error or object-defined error

    Leelnich, can you explain the red lines of code you made? Basically what will happen? Because I'm still learning VBA.

  9. #9
    Forum Expert leelnich's Avatar
    Join Date
    03-20-2017
    Location
    Delaware, USA
    MS-Off Ver
    Office 2016
    Posts
    2,807

    Re: Application error or object-defined error

    On Error Resume Next - Says "If an error occurs in a line of code, ignore it and execute next line."
    Set MATCHES = .Offset(1, 0).SpecialCells(12) - This is the line that will generate an error if no rows meet your criteria.
    If an error DOES occur, then the line will not successfully assign a value to the variable MATCHES...
    If Not MATCHES Is Nothing Then MATCHES.Copy Sheets("DTE").Range("A2")-... which we test for here. The result?- we only copy if we find rows.
    On Error GoTo 0 - Turn off the Error Handling, so other errors that might occur will be handled normally.

    You could even take some alternative action if the error occurs:
    Please Login or Register  to view this content.
    Last edited by leelnich; 02-04-2018 at 09:03 PM.

  10. #10
    Forum Contributor
    Join Date
    09-19-2017
    Location
    London
    MS-Off Ver
    2015
    Posts
    169

    Re: Application error or object-defined error

    I have tried it on my Excel but nothing happened. The autofilter is not working. Is there any possibility that this code only works for actual text, not linked data? Because in DTE_Raw, my data is linked to some other files.

+ 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. [SOLVED] Error message: Run-Time error '1004 '; application-defined or object-defined error
    By Davasu in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 10-23-2015, 06:52 AM
  2. Replies: 1
    Last Post: 10-22-2015, 05:50 AM
  3. VBA ERROR: run time error 1004: Application-defined or Object-defined error in excel 2013
    By AnanthKrishna in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 02-13-2015, 06:16 AM
  4. [SOLVED] Error " Run-time error '1004': application defined or object defined error
    By lengwer in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 09-11-2013, 07:26 AM
  5. [SOLVED] Error 1004: Application-defined or object-defined error on Range(Cells(x,y)) syntax
    By winch in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 01-04-2013, 11:02 AM
  6. Replies: 2
    Last Post: 09-12-2012, 01:01 PM
  7. Replies: 0
    Last Post: 05-14-2012, 11:59 PM

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