+ Reply to Thread
Results 1 to 6 of 6

Macro to delete rows

  1. #1
    Registered User
    Join Date
    02-29-2008
    Posts
    14

    Macro to delete rows

    I recorded a macro to delete some rows that are headers and subtotals and merged at the same time. It worked, but when I need to use it again will not work because the rows have changed. Every time I export the database to excel those subtotals and merged rows are in different row numbers.
    How can I have a macro to delete those rows when they change all the time?
    I'm attaching a sample of my excel and I need to delete every single row that is shaded and merged that has a header and subtotal and leave only the data in the other cells.
    Is it possible ?

    Thanksbook.GIF

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

    Re: Macro do delete rows

    You posted a picture, not a workbook. Post an actual workbook with two sheets in it, a BEFORE and an AFTER so we can see exactly what you're trying to accomplish. I think I understand, but people's workbooks often reveal extra problems.

    Click on GO ADVANCED and use the paperclip icon to open the upload window.

    View Pic
    _________________
    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!)

  3. #3
    Registered User
    Join Date
    02-29-2008
    Posts
    14

    Re: Macro to delete rows

    Thanks for replying.
    I thought the picture would give an idea.
    I'm attaching the excel.
    In ORIGINAL worksheet is the data I import and in the FINAL is what I want to have to be able to manipulate without having to delete all those merged/subtotal/headers rows all the time.
    I hope it helps.
    Attached Files Attached Files
    Last edited by psychson; 08-23-2013 at 02:35 PM.

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

    Re: Macro to delete rows

    This should do it, it applies a filter to the data and leaves only rows showing that are "blank" in column B. Then it deletes all visible rows.

    Please Login or Register  to view this content.

  5. #5
    Registered User
    Join Date
    02-29-2008
    Posts
    14

    Re: Macro to delete rows

    Thanks, but somehow it did not worked as I thought.
    I used it with my real data and not the worksheet sample I attached, which is basically the same, but more than 5000 rows.
    It gave me an error:
    RUN-TIME ERROR 40036
    APPLICATION-DEFINED OR
    OBJECT-DEFINED ERROR
    When I click DEBUG takes me to the Code and Highlights: AutoFilterMode = False

    If I run in the Sample I sent you I get error:
    RUN TIME ERROR 1004
    DELETE METHOD OF RANGE CLASS FAILED
    When I click DEBUG takes me to the Code and Highlights:Range("A2:A" & LR).EntireRow.Delete xlShiftUp

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

    Re: Macro to delete rows

    I can test on whatever data you provide.

+ 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] Macro to delete rows with certain details in, but to keep other rows
    By Robert110 in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 03-08-2013, 03:20 PM
  2. Macro to delete certain columns and delete rows based on time in another column
    By beepbeep27 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 05-12-2012, 11:47 AM
  3. Replies: 13
    Last Post: 08-23-2011, 11:00 AM
  4. How to make my macro delete rows? It currently hides the rows instead of deleting.
    By Majkataxmk in forum Excel Programming / VBA / Macros
    Replies: 16
    Last Post: 05-20-2010, 01:14 PM
  5. [SOLVED] Macro to select 4 entire rows and then delete rows
    By Scott Viney in forum Excel General
    Replies: 3
    Last Post: 09-22-2005, 03:05 PM

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