+ Reply to Thread
Results 1 to 4 of 4

Delete Entire Row based on Selection

  1. #1
    Forum Expert
    Join Date
    11-27-2007
    Location
    New Jersey, USA
    MS-Off Ver
    2013
    Posts
    1,669

    Delete Entire Row based on Selection

    I have a worksheet where I have restricted the users from scrolling around beyond a certain range.
    Because of that the user is prevented from selecting an entire row.
    There are some cases where the user should be able to delete entire row or range of rows.

    How can I allow them to select say cells "C17:C35" [they would just hoghlight the range] and hit ctrl+d; which would trigger a macro and the macro in turn would delete all the rows in that selection [rows 17 through 35]?

    I know some basic codes for deleting entire rows, but I don't know how to read first and last row of the selection under Target property.

    Thanks,
    modytrane
    Last edited by modytrane; 05-27-2009 at 04:42 PM. Reason: solved

  2. #2
    Forum Expert Paul's Avatar
    Join Date
    02-05-2007
    Location
    Wisconsin
    MS-Off Ver
    2016/365
    Posts
    6,885

    Re: Delete Entire Row based on Selection

    Hi Modytrane,

    The following line of code will delete all rows that are currently selected:
    Please Login or Register  to view this content.
    You may need to unprotect the sheet first, then re-protect it afterwards if you have that turned on.
    Please Login or Register  to view this content.

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

    Re: Delete Entire Row based on Selection

    Along with that, if this macro already exists, do this to add the keyboard shortcut:

    Press Alt-F8
    Highlight the Macro in the list
    Click on Options
    _________________
    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!)

  4. #4
    Forum Expert
    Join Date
    11-27-2007
    Location
    New Jersey, USA
    MS-Off Ver
    2013
    Posts
    1,669

    Re: Delete Entire Row based on Selection

    Thanks Paul and JB,
    It works.
    I already had the worksheet.unprotect and the shortcut programmed for the macro. Besides deleting the rows, I had to restore some formulas as well, cause deleting the formulas was changing some range references in my SUM formulas.

    Thanks to both of you,
    modytrane

+ Reply to Thread

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