+ Reply to Thread
Results 1 to 7 of 7

IF-Then-Else loop stopping and producing runtime error 1004

  1. #1
    Registered User
    Join Date
    07-31-2013
    Location
    England
    MS-Off Ver
    Excel 2010
    Posts
    21

    Smile IF-Then-Else loop stopping and producing runtime error 1004

    Hello,

    I am new to posting on the forums, although I have found responses to other threads very helpful for previous queries I have had. So thanks to all those that post answers on this site

    I cannot find anywhere help with my current issue. So any advice would be much appreciated.

    The purpose of the macro is to search a data range. Where the cell contains 'Y' I want it to keep the row. Where the cell contains anything else I would like the row deleted. Please see below my code:

    Please Login or Register  to view this content.
    I didn't know how to instruct excel to just leave the row, so as a placeholder I made it turn bold.

    When I run the macro it clears all the rows up to the first 'Y' it comes across. Then it stops and a run time 1004 error. I am sure it is a simple mistake I am making. Any advice would be much appreciated

    Thanks

  2. #2
    Forum Expert tigeravatar's Avatar
    Join Date
    03-25-2011
    Location
    Colorado, USA
    MS-Off Ver
    Excel 2003 - 2013
    Posts
    5,361

    Re: IF-Then-Else loop stopping and producing runtime error 1004

    Optiprime,

    Welcome to the forum!
    The issue is that you need to set if the Bold is True or False, so change the line to:
    Please Login or Register  to view this content.
    Hope that helps,
    ~tigeravatar

    Forum Rules: How to use code tags, mark a thread solved, and keep yourself out of trouble

  3. #3
    Forum Expert tigeravatar's Avatar
    Join Date
    03-25-2011
    Location
    Colorado, USA
    MS-Off Ver
    Excel 2003 - 2013
    Posts
    5,361

    Re: IF-Then-Else loop stopping and producing runtime error 1004

    As for using a placeholder, you could simply have a blank line.

    Instead of that though, look for the opposite. In other words, instead of looking for "Y" and only deleting rows that don't match, look for <> "Y" (does not equal "Y") and only delete rows that match, like so:
    Please Login or Register  to view this content.

  4. #4
    Forum Expert
    Join Date
    07-15-2012
    Location
    Leghorn, Italy
    MS-Off Ver
    Excel 2010
    Posts
    3,431

    Re: IF-Then-Else loop stopping and producing runtime error 1004

    need a sample file, your code works on my test sheet
    If solved remember to mark Thread as solved

  5. #5
    Registered User
    Join Date
    07-31-2013
    Location
    England
    MS-Off Ver
    Excel 2010
    Posts
    21

    Re: IF-Then-Else loop stopping and producing runtime error 1004

    Hey all. Many thanks for all your replies. I used Tigeravatar's solution and it works great.

    Thanks again

  6. #6
    Forum Expert tigeravatar's Avatar
    Join Date
    03-25-2011
    Location
    Colorado, USA
    MS-Off Ver
    Excel 2003 - 2013
    Posts
    5,361

    Re: IF-Then-Else loop stopping and producing runtime error 1004

    You're very welcome

    If that takes care of your need, please mark this thread as solved.
    How to mark a thread Solved
    New quick method:
    Select Thread Tools-> Mark thread as Solved. To undo, select Thread Tools-> Mark thread as Unsolved.

    Or you can use this way:
    Go to the first post
    Click edit
    Click Go Advanced
    Just below the word "Title" you will see a dropdown with the words "No prefix"
    Change to "Solved"
    Click Save

  7. #7
    Registered User
    Join Date
    07-31-2013
    Location
    England
    MS-Off Ver
    Excel 2010
    Posts
    21

    Re: IF-Then-Else loop stopping and producing runtime error 1004

    Understood, set as solved now

+ 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] Range error in code, runs alone but not inside my full program, giving runtime error 1004
    By charizzardd in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 08-23-2012, 03:34 PM
  2. Array loop producing error "Run time error '1004'"
    By jeskit in forum Excel Programming / VBA / Macros
    Replies: 12
    Last Post: 05-06-2011, 08:56 AM
  3. Runtime 1004 error
    By meister14 in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 07-24-2010, 11:11 AM
  4. runtime error 1004
    By andy1510 in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 06-02-2010, 10:14 AM
  5. [SOLVED] Excel 2003 Macro Error - Runtime error 1004
    By Cow in forum Excel General
    Replies: 2
    Last Post: 06-07-2005, 09:05 AM

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