+ Reply to Thread
Results 1 to 11 of 11

IF statement...Delete entire row

  1. #1
    Forum Contributor
    Join Date
    07-12-2013
    Location
    Los angeles, CA
    MS-Off Ver
    Excel 2007
    Posts
    109

    IF statement...Delete entire row

    My code is giving me an error on the line containing: cell.EntireRow.Delete Shift:=xlup

    The error states: "Delete method of Range class failed."

    Also, the cell.address = A128 so it is selecting the correct cell I want it to.

    Do I need to have the code select the row, and then delete it?

    Please Login or Register  to view this content.

  2. #2
    Forum Contributor
    Join Date
    03-28-2013
    Location
    *
    MS-Off Ver
    Excel 2010
    Posts
    226

    Re: IF statement...Delete entire row

    May this can help you,

    Run the code and select the range that you wanted to delete.......done

    Please Login or Register  to view this content.

  3. #3
    Forum Contributor
    Join Date
    07-12-2013
    Location
    Los angeles, CA
    MS-Off Ver
    Excel 2007
    Posts
    109

    Re: IF statement...Delete entire row

    I'm already using a userform for this particular code, so I'm just looking to see if the syntax of my command is incorrect (without changing the input method of the code)

    linenumber is the variable containing the bus line number that is desired to be removed from the worksheet (I work for a transit company)

  4. #4
    Valued Forum Contributor WasWodge's Avatar
    Join Date
    08-02-2010
    Location
    Hampshire,England
    MS-Off Ver
    Office 365 and Office 2010
    Posts
    882

    Re: IF statement...Delete entire row

    Is the sheet protected?
    If my solution worked (or not) please let me know. If your question is answered then please remember to mark it solved

    Computers are like air conditioners. They work fine until you start opening windows. ~Author Unknown

  5. #5
    Forum Expert Solus Rankin's Avatar
    Join Date
    05-24-2013
    Location
    Hollywood, CA
    MS-Off Ver
    Win7 Office 2010 VS Express 2012
    Posts
    2,655

    Re: IF statement...Delete entire row

    Worked fine for me. What is rngtest set to?
    Thanks,
    Solus


    Please remember the following:

    1. Use [code] code tags [/code]. It keeps posts clean, easy-to-read, and maintains VBA formatting.
    Highlight the code in your post and press the # button in the toolbar.
    2. Show appreciation to those who have helped you by clicking below their posts.
    3. If you are happy with a solution to your problem, mark the thread as [SOLVED] using the tools at the top.

    "Slow is smooth, smooth is fast."

  6. #6
    Forum Contributor
    Join Date
    07-12-2013
    Location
    Los angeles, CA
    MS-Off Ver
    Excel 2007
    Posts
    109

    Re: IF statement...Delete entire row

    No, it is not.

  7. #7
    Forum Contributor
    Join Date
    07-12-2013
    Location
    Los angeles, CA
    MS-Off Ver
    Excel 2007
    Posts
    109

    Re: IF statement...Delete entire row

    Please Login or Register  to view this content.

  8. #8
    Forum Contributor
    Join Date
    07-12-2013
    Location
    Los angeles, CA
    MS-Off Ver
    Excel 2007
    Posts
    109

    Re: IF statement...Delete entire row

    Ah, here's what happens. The macro runs perfectly the first time, but when I rerun it, that error occurs.

  9. #9
    Forum Contributor
    Join Date
    07-12-2013
    Location
    Los angeles, CA
    MS-Off Ver
    Excel 2007
    Posts
    109

    Re: IF statement...Delete entire row

    Nevermind, solved it myself. The code converted a range to a table and did not convert it back to a normal range at the end of the code. Thus, when I try to delete or add rows the second time around, Excel doesn't allow it to run properly. Thanks for the help, though!

  10. #10
    Valued Forum Contributor WasWodge's Avatar
    Join Date
    08-02-2010
    Location
    Hampshire,England
    MS-Off Ver
    Office 365 and Office 2010
    Posts
    882

    Re: IF statement...Delete entire row

    If you have say 6 cells with the linenumber value in consecutive rows does the code delete them all?

  11. #11
    Forum Expert JBeaucaire's Avatar
    Join Date
    03-21-2004
    Location
    Bakersfield, CA
    MS-Off Ver
    2010, 2016, Office 365
    Posts
    33,492

    Re: IF statement...Delete entire row

    I've marked this thread as SOLVED for you.
    Next time, select Thread Tools from the links above to mark a thread as SOLVED. Thanks.
    _________________
    Microsoft MVP 2010 - Excel
    Visit: Jerry Beaucaire's Excel Files & Macros

    If you've been given good help, use the icon below to give reputation feedback, it is appreciated.
    Always put your code between code tags. [CODE] your code here [/CODE]

    ?None of us is as good as all of us? - Ray Kroc
    ?Actually, I *am* a rocket scientist.? - JB (little ones count!)

+ 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] If Or statement to check cell text and delete entire row if text is found
    By VBA FTW in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 08-08-2013, 11:46 AM
  2. [SOLVED] Delete cell only with certain critria. Don't want to delete entire row, the celsl only
    By RobertOHare in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 07-16-2013, 04:18 AM
  3. [SOLVED] Delete Entire Row using VBA
    By Simon.Ward in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 03-05-2013, 05:28 AM
  4. delete entire row if this AND if this...?
    By Armitage2k in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 09-16-2009, 02:50 PM
  5. Delete entire row when cell says delete
    By Macdave_19 in forum Excel Programming / VBA / Macros
    Replies: 8
    Last Post: 09-27-2007, 11:46 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