+ Reply to Thread
Results 1 to 9 of 9

Macros Button to Clear Rows of Data

  1. #1
    Registered User
    Join Date
    08-19-2012
    Location
    Pennsylvania, USA
    MS-Off Ver
    Excel 2010
    Posts
    62

    Macros Button to Clear Rows of Data

    I can't figure out how to add an error message to a button I have to clear rows of data.
    The code works, but I only want the user to be able to delete row ranges from 8 onward.

    If the user tries to delete any row range between 1:7 (1 through 7), then I want an error message to come up saying that "You can't delete any rows between 1 and 7."

    Any help would be greatly appreciated.

    Here's my code:

    Please Login or Register  to view this content.


    This is my feeble attempt to add the error message, but it doesn't work. It's hard for me to figure out because the user enters the data in row ranges such as: "8:22" .

    Please Login or Register  to view this content.

  2. #2
    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: Macros Button to Clear Rows of Data

    Hi, lottidotti,

    check the row number for the first cell of the selected area:
    Please Login or Register  to view this content.
    You need to check Abort prior to this check for ending.

    Ciao,
    Holger

  3. #3
    Registered User
    Join Date
    08-19-2012
    Location
    Pennsylvania, USA
    MS-Off Ver
    Excel 2010
    Posts
    62

    Re: Macros Button to Clear Rows of Data

    Thank you Holger,
    It worked perfectly!

    I have another worksheet that I need to do the same thing with (post error message if the user tries to delete rows 1-7). However, this code has the user input individual rows that are comma separated like this (8,11,23).

    Any ideas on how to do the same thing with this code?

    Please Login or Register  to view this content.

  4. #4
    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: Macros Button to Clear Rows of Data

    Hi, lottidotti,

    why change from Type:=8 (Range) to 1+2? If you use Type:=8 and mark the rows you could easily work on that.

    The solution may either be use Type:=8 for Application.InputBox or split up the rows delivered from the string and check for their numbers in the array or double the row numbers for the string like ("8:8, 11:11, 21:21"). The split is used later on for clearing contents in your code.

    Ciao,
    Holger

  5. #5
    Registered User
    Join Date
    08-19-2012
    Location
    Pennsylvania, USA
    MS-Off Ver
    Excel 2010
    Posts
    62

    Re: Macros Button to Clear Rows of Data

    Hi Holger,
    The user requires the 1+2 rather than the Type:=8 for the other worksheet because they have a huge amount of data that needs to stay in order, but only have a row deleted here and there without disturbing the rest of the worksheet.

    Anyways, I need to keep it with the user entering rows to delete as (8,12,51,127,etc.)
    I can't do the 8:8, 11:11, split method.
    So I'm not quite sure how to adjust my code so they can't delete rows 1-7.
    Thanks for your help.
    I think I'll be pulling out my hair for a while with this one!

    ---------- Post added at 09:06 AM ---------- Previous post was at 08:57 AM ----------

    Do you know of a way that I could search the string for the text or numbers "1,2,3,4,5,6,7" without it confusing it with 11,12,13, etc.

    I saw that someone else had some code like this checking for specific text within a string. (See below)

    Please Login or Register  to view this content.

  6. #6
    Registered User
    Join Date
    08-19-2012
    Location
    Pennsylvania, USA
    MS-Off Ver
    Excel 2010
    Posts
    62

    Re: Macros Button to Clear Rows of Data

    Do you know of a way that I could search the string for the text or numbers "1,2,3,4,5,6,7" without it confusing it with 11,12,13, etc.

    I saw that someone else had some code like this checking for specific text within a string. (See below)

    Please Login or Register  to view this content.

  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: Macros Button to Clear Rows of Data

    Hi, lottidotti,

    why donīt you use the approach of splitting the string?

    I had to work a bit on the code as I use a non-englisch version of Excel:

    Please Login or Register  to view this content.
    Maybe another idea could be to lock rows 1 to 7 and use a code like
    Please Login or Register  to view this content.
    to avoid Rows 1:7 to be selected at all.

    Ciao,
    Holger

  8. #8
    Registered User
    Join Date
    08-19-2012
    Location
    Pennsylvania, USA
    MS-Off Ver
    Excel 2010
    Posts
    62

    Re: Macros Button to Clear Rows of Data

    Hi Holger,
    I used your split code and it worked great!
    Thank you so much for helping me.
    I'm a newbie, so I didn't know how to write the split code.
    You saved me so many headaches!
    Cheers!

  9. #9
    Forum Expert Cutter's Avatar
    Join Date
    05-24-2004
    Location
    Ontario,Canada
    MS-Off Ver
    Excel 2010
    Posts
    6,451

    Re: Macros Button to Clear Rows of Data

    @ lottidotti

    Based on your last post it seems that you are satisfied with the solution(s) you've received but you haven't marked your thread as SOLVED. I'll do that for you now but please keep in mind for your future threads that Rule #9 requires you to do that yourself. If your problem has not been solved you can use Thread Tools (located above your first post) and choose "Mark this thread as unsolved".
    Thanks.

    Also, as a new member of the forum, you may not be aware that you can thank those who have helped you by clicking the small star icon located in the lower left corner of the post in which the help was given. By doing so you can add to the reputation(s) of those who helped.

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

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