Results 1 to 3 of 3

Macro to add or delete rows in a worksheet

Threaded View

  1. #1
    Registered User
    Join Date
    09-19-2012
    Location
    New Zealand
    MS-Off Ver
    Excel 2003
    Posts
    2

    Macro to add or delete rows in a worksheet

    I have just started my foray into VBA. I have been trying to figure out an elegant way to add or delete rows in a worksheet based on the contents of that row, but have a runaway macro at the moment.

    I have attached the example for reference.

    Book1 links to the rows in Book2 (the number of rows in Book2 varies from day to day, but always finishes the same - a blank line and then another line with Report Total =). Manually I go through each of the Sheets and either delete rows or add rows so that the last row of each sheet in Book1 reflects the last sheet of Book2 (The line with Report Total in Column B). I now have 41 sheets to review and it is getting time consuming.

    I have written a macro that goes through each sheet and copies the last row down. This process should continue until the "Report Total =" line is reached. Unfortunately it doesn't and carries on adding lines. I haven't worked out how to delete extra lines either.

    The way I see the logic is as follows:

    If the last row is not blank (0) copy the row down and keep going until the row with Report Total = in column B appears.
    If the last row is blank (0) delete the row and keep going until the last row has Report Total = in column B.
    If the last row has Report Total = in column B, then stop and go onto the next sheet.

    Any assistance would be appreciated.

    Thanks
    Attached Files Attached Files
    Last edited by johncullen01; 09-20-2012 at 11:12 PM.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

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