+ Reply to Thread
Results 1 to 8 of 8

macro emptying table also to work when table is empty

  1. #1
    Registered User
    Join Date
    10-30-2012
    Location
    amsterdam
    MS-Off Ver
    Excel 2010
    Posts
    15

    macro emptying table also to work when table is empty

    Hi,

    I've written a macro that clears all data from several sheets so you have a blank sheet to start from the next week we run reports.
    part of the data resides in tables. however not always all tables will be filled.
    so when this part of the macro runs

    Sheets("TBL WT").Select
    Rows("2:150").Select
    Selection.Delete Shift:=xlUp

    and the table is empty, it has no data to remove, and therefor it doesnt and the macro stops running ( I have put it in the last position so it kinda works still)
    I have a copy of this table ( callet TBL DT) which is usually filled with a couple of rows of data and that does empty with the same code.
    so the only issie there is is that it 'jams' when there is no data in the table.

    is there a way to rewrite the code so it does not delete when the rows are empty and the code works as meant when there is data to delete? maybe?

    thanks!
    Pascalle.

  2. #2
    Registered User
    Join Date
    02-20-2014
    Location
    Wales
    MS-Off Ver
    Excel 2010
    Posts
    87

    Re: macro emptying table also to work when table is empty

    Could you not put an if statement in to check if the rows are empty first?

  3. #3
    Registered User
    Join Date
    10-30-2012
    Location
    amsterdam
    MS-Off Ver
    Excel 2010
    Posts
    15

    Re: macro emptying table also to work when table is empty

    I guess, but how?

    =IF ISBLANK and then? what is the code for : 'do nothing', or ignore the code. ?

  4. #4
    Registered User
    Join Date
    02-20-2014
    Location
    Wales
    MS-Off Ver
    Excel 2010
    Posts
    87

    Re: macro emptying table also to work when table is empty

    Try something along these lines...

    Please Login or Register  to view this content.
    This assumes that if your table is empty then only the first row needs to be checked. If it is empty, the sub is exited, otherwise it processes your code.

  5. #5
    Registered User
    Join Date
    10-30-2012
    Location
    amsterdam
    MS-Off Ver
    Excel 2010
    Posts
    15

    Re: macro emptying table also to work when table is empty

    ah that makes sense, but what if i dont want it to exit the sub entirely, but only part of the code in the sub? ( I can place this bit of the code at the end, so exiting the sub will work, butt the identical table ( "DT") might have instances where it is empty too, so I'd like to build it into that part of the macro as well.

    asking too much?

  6. #6
    Registered User
    Join Date
    10-30-2012
    Location
    amsterdam
    MS-Off Ver
    Excel 2010
    Posts
    15

    Re: macro emptying table also to work when table is empty

    does the answer lie in 'resume next'?

  7. #7
    Registered User
    Join Date
    02-20-2014
    Location
    Wales
    MS-Off Ver
    Excel 2010
    Posts
    87

    Re: macro emptying table also to work when table is empty

    Quote Originally Posted by pallie View Post
    ah that makes sense, but what if i dont want it to exit the sub entirely, but only part of the code in the sub? ( I can place this bit of the code at the end, so exiting the sub will work, butt the identical table ( "DT") might have instances where it is empty too, so I'd like to build it into that part of the macro as well.

    asking too much?
    You could use Go To:

    Please Login or Register  to view this content.

  8. #8
    Registered User
    Join Date
    10-30-2012
    Location
    amsterdam
    MS-Off Ver
    Excel 2010
    Posts
    15

    Re: macro emptying table also to work when table is empty

    perfect! thanks!!

+ 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. Change macro to write to next empty row of table?
    By humboldtguy in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 03-20-2014, 03:17 AM
  2. UserForm to transfer items from one table to another table in the next empty cell...
    By aneese11 in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 12-04-2012, 10:31 AM
  3. Macro that will find the next empty row in a table
    By Anon415 in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 11-15-2012, 09:49 AM
  4. Pivot table macro does not work
    By ben2010 in forum Excel Programming / VBA / Macros
    Replies: 13
    Last Post: 03-01-2010, 07:06 PM
  5. to make a pivot table to work with an adjoining table
    By byronova in forum Excel General
    Replies: 2
    Last Post: 09-06-2009, 10:47 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