+ Reply to Thread
Results 1 to 12 of 12

Problem Deleting Entire Rows

  1. #1
    Forum Contributor
    Join Date
    10-02-2008
    Location
    Berkeley, CA
    MS-Off Ver
    Windows 2007
    Posts
    105

    Problem Deleting Entire Rows

    I have a sheet. I select all of it and "Deleted" it's contents a couple of different ways.

    After I've "deleted" and run this code
    With ActiveSheet
    Last_Row = .Range("A1").SpecialCells(xlCellTypeLastCell).Row
    End With

    "Last_Row" comes up with 3163 in it. How do I get it to say "0"?

    The one solution I've found (but this isn't really practical) is to delete the rows, save the entire work sheet, close it, and read it back in. But I need to do these deletions under VBA code control.

    Tnx, Mac

  2. #2
    Forum Expert Mumps1's Avatar
    Join Date
    10-10-2012
    Location
    Toronto, Canada
    MS-Off Ver
    Excel 2010, 2013
    Posts
    7,821

    Re: Problem Deleting Entire Rows

    How did you delete the contents? Did you delete the rows or clear the cell contents?
    You can say "THANK YOU" for help received by clicking the Star symbol at the bottom left of the helper's post.
    Practice makes perfect. I'm very far from perfect so I'm still practising.

  3. #3
    Forum Contributor
    Join Date
    10-02-2008
    Location
    Berkeley, CA
    MS-Off Ver
    Windows 2007
    Posts
    105

    Re: Problem Deleting Entire Rows

    I did it by deleting all the rows by selecting them first, not clearing.

  4. #4
    Forum Contributor
    Join Date
    08-09-2012
    Location
    British Columbia
    MS-Off Ver
    Excel 2010
    Posts
    189

    Re: Problem Deleting Entire Rows

    don't think Excel will find rows less than 1.

    put .UsedRange on a line right above your Last_Row =.... line

  5. #5
    Forum Expert Mumps1's Avatar
    Join Date
    10-10-2012
    Location
    Toronto, Canada
    MS-Off Ver
    Excel 2010, 2013
    Posts
    7,821

    Re: Problem Deleting Entire Rows

    If you deleted the rows, that should have worked. You'll never get Last_Row to be equal to zero. Can you post a copy of your file?

  6. #6
    Forum Contributor
    Join Date
    10-02-2008
    Location
    Berkeley, CA
    MS-Off Ver
    Windows 2007
    Posts
    105

    Unhappy Re: Problem Deleting Entire Rows

    So here is an example. Download "Book1.xlsm". Run the Macro "A" and read the messages.

    The Macro begins with a delete. Then it searches for the LastRow and the LastCol in the LastRow it found.

    I think the LastRow should be 3, but the computer doesn't think so.

    Really could use some help here. Thanks,

    Mac
    Attached Files Attached Files

  7. #7
    Forum Guru HaHoBe's Avatar
    Join Date
    02-19-2005
    Location
    Hamburg, Germany
    MS-Off Ver
    work: 2016 on Win10 (notebook), private: 2019 on Win10 (desktop), 2019 on Win11 (notebook)
    Posts
    8,197

    Re: Problem Deleting Entire Rows

    Hi, Mac,

    itīs the normal behaviour of UsedRange to expand and notice that but not get the deletion correct (only after saving the workbook or resetting the last cell (see Reset All Lastcells in the Active Workbook on that) or maybe use
    Please Login or Register  to view this content.
    instead.

    Ciao,
    Holger
    Use Code-Tags for showing your code: [code] Your Code here [/code]
    Please mark your question Solved if there has been offered a solution that works fine for you

  8. #8
    Forum Expert Mumps1's Avatar
    Join Date
    10-10-2012
    Location
    Toronto, Canada
    MS-Off Ver
    Excel 2010, 2013
    Posts
    7,821

    Re: Problem Deleting Entire Rows

    Hi Mac. When I ran macro A, it reported that the last row was 3 as you expected.

  9. #9
    Forum Guru HaHoBe's Avatar
    Join Date
    02-19-2005
    Location
    Hamburg, Germany
    MS-Off Ver
    work: 2016 on Win10 (notebook), private: 2019 on Win10 (desktop), 2019 on Win11 (notebook)
    Posts
    8,197

    Re: Problem Deleting Entire Rows

    Hi, Mumps,

    I stated that after a save the UsedRange would be restored (as it happens automaticly when you close the workbook). Did you mind to add some contents to the range before running the macro? Iīm afraid you didnīt.

    Ciao,
    Holger

  10. #10
    Forum Expert Mumps1's Avatar
    Join Date
    10-10-2012
    Location
    Toronto, Canada
    MS-Off Ver
    Excel 2010, 2013
    Posts
    7,821

    Re: Problem Deleting Entire Rows

    My apologies, Holger. You are perfectly correct.

  11. #11
    Forum Contributor
    Join Date
    10-02-2008
    Location
    Berkeley, CA
    MS-Off Ver
    Windows 2007
    Posts
    105

    Re: Problem Deleting Entire Rows

    Holger, You nailed it. Thanks for the Wallenberg tip.

    Now, how do I mark this thread closed?
    Last edited by CaptMac; 12-17-2014 at 11:20 AM.

  12. #12
    Forum Guru HaHoBe's Avatar
    Join Date
    02-19-2005
    Location
    Hamburg, Germany
    MS-Off Ver
    work: 2016 on Win10 (notebook), private: 2019 on Win10 (desktop), 2019 on Win11 (notebook)
    Posts
    8,197

    Re: Problem Deleting Entire Rows

    Hi, Mac,

    from the FAQ:
    To mark your thread solved do the following:
    New Method
    -Go to the top of the first post
    -Select Thread Tools
    -Select Mark thread as Solved

    Old Method
    - Go to the first post
    - Click edit
    - Click Advance
    - Just below the word "Title:" you will see a dropdown with the word No prefix.
    - Change to Solve
    - Click Save
    Ciao,
    Holger

+ 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. Deleting entire rows when a cell in that row contains #N/A
    By colin.dickson in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 02-15-2012, 10:13 AM
  2. VBA for deleting entire rows
    By TheTalentedMrRipley in forum Excel General
    Replies: 3
    Last Post: 11-04-2010, 07:31 PM
  3. Deleting rows based on max value in entire row
    By form in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 10-27-2010, 09:27 AM
  4. problem deleting entire row based on a condition
    By mehdoush in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 05-18-2009, 09:26 AM
  5. Deleting Entire Rows
    By gavsta in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 05-19-2005, 12:45 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