+ Reply to Thread
Results 1 to 4 of 4

How to delete all rows except Row 1 and a variable row?

  1. #1
    Forum Contributor
    Join Date
    09-20-2012
    Location
    Norge
    MS-Off Ver
    Excel 2007
    Posts
    114

    How to delete all rows except Row 1 and a variable row?

    Hello,

    I want to start fresh on a worksheet whenever unloading the userform.

    This means deleting all rows on the active worksheet except:
    - Row 1 and
    - the row that contains the text "Totalt:" in column B. This row is a variable, depending on how many items (rows inserted in between) have been added by the user.

    What happens is that every time an option is chosen in a configurator in the userform a row containing data is inserted between the 2 rows mentioned above.

    Thus when unloading the userform I want it to start at scratch again, just containing data in the rows above. This is my DEFAULT state if you like.


    This is a picture of my desired DEFAULT state of the worksheet:

    Screenshot 2014-11-30 16.41.43.png


    Thanks in advance

  2. #2
    Forum Expert
    Join Date
    12-14-2012
    Location
    London England
    MS-Off Ver
    MS 365 Office Suite.
    Posts
    8,448

    Re: How to delete all rows except Row 1 and a variable row?

    This is quite simple

    Just paste this code into the userforms vba module.

    Please Login or Register  to view this content.
    Last edited by mehmetcik; 11-30-2014 at 01:13 PM.

  3. #3
    Forum Expert
    Join Date
    07-31-2010
    Location
    California
    MS-Off Ver
    Excel 2007
    Posts
    4,070

    Re: How to delete all rows except Row 1 and a variable row?

    Please Login or Register  to view this content.

  4. #4
    Forum Contributor
    Join Date
    09-20-2012
    Location
    Norge
    MS-Off Ver
    Excel 2007
    Posts
    114

    Re: How to delete all rows except Row 1 and a variable row?

    Hi guys,

    Thanks for your solutions. both didnīt work 100% as a wanted but this might because maybe I wasnīt completely clear. However I add a line of code to stnkynts solution and now it workes like a charm.

    mehmetcik: Your code did not clear the content of row 2 itself. But off course this would also be easy to fix by adding a line of code to simply ClearContents of row 2.
    After some more extensive testing I found that after a couple of times i suddenly get the Run-time error '91': Object variable of With block variable not set. In debugging mode the 3 lines under Columns("B:B").select are marked yellow.


    In other words, both codes does the work!

    Thank you so much guys

    This is the code I ended up using that seems to be the most stable solution so far:

    Please Login or Register  to view this content.
    Last edited by tnuis; 11-30-2014 at 03:02 PM.

+ 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] Select variable range; identify & delete rows with blank cells
    By alter54 in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 08-28-2013, 04:40 PM
  2. How do I delete all rows containing a certain (variable) text string?
    By needananswer in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 02-22-2013, 05:04 PM
  3. delete duplicate rows, delete empty rows
    By loade in forum Excel Programming / VBA / Macros
    Replies: 12
    Last Post: 05-03-2012, 05:42 AM
  4. Replies: 6
    Last Post: 04-14-2012, 04:07 AM
  5. [SOLVED] Re: Variable criteria to delete rows
    By Coal Miner in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 03-09-2006, 05:35 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