+ Reply to Thread
Results 1 to 10 of 10

Using Check Box To Delete Row

  1. #1
    Registered User
    Join Date
    12-19-2008
    Location
    Boston
    Posts
    7

    Using Check Box To Delete Row

    I'm trying to repurpose this script I found so it deletes the row in an excel spreadsheet when it is checked. The current script just hides them. I'd also like to see ifthere is a way to have the row number automaticaly referenced via the checkboxes cell link so I woudn't have to make a custom macro for each row I want to have he checkbox delete feature.

    Any ideas?

    Thanks,

    Mark

    Here is what I'm trying to repurpose:

    Sub HideRows()
    If Rows("9").RowHeight = 0 Then
    Rows("9").Hidden = False
    ActiveSheet.CheckBoxes("Check Box 346").Visible = True
    Else
    Rows("9").Hidden = True
    ActiveSheet.CheckBoxes("Check Box 346").Visible = False
    End If
    End Sub

  2. #2
    Forum Expert Palmetto's Avatar
    Join Date
    04-04-2007
    Location
    South Eastern, USA
    MS-Off Ver
    XP, 2007, 2010
    Posts
    3,978

    Re: Using Check Box To Delete Row

    May I suggest that you not use check boxes? They really clutter up a worksheet if you too many of them and there is "neater" alternative that facilates the VBA code much better.

    In whatever column the checkboxes are made to appear in, let cells in that column serve as a Marlett check box. Meaning the cells are formatted using the Marlett font, which then allows you type an "a" into the cell to create a checkmark.

    The VBA code only needs to check if the cell on a row has a value and delete the row if it does.

    See attached workbook for an example.
    Included is this code which will automatically format the cells in A:A100 to Marlett and enter the character "a" to produce the checkmark. The second bit of code will delete row when the checkbox cell is selected.

    Adjust range references per your requirements. It is currently set to work in column-A rows 2:100
    Please Login or Register  to view this content.

  3. #3
    Forum Expert shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2010, 2019
    Posts
    40,689

    Re: Using Check Box To Delete Row

    mcurrier,

    Please take a few minutes to read the forum rules, and then edit your post to add code tags.

    I second Palmetto's suggestion for Marlett checkboxes.
    Entia non sunt multiplicanda sine necessitate

  4. #4
    Registered User
    Join Date
    12-19-2008
    Location
    Boston
    Posts
    7

    Re: Using Check Box To Delete Row

    Palmetto,

    Thanks, I pasted in the coded you provided. I can't seem to get excel to save it is a runable macro. I have attached a spreadsheet example.

    -Mark
    Attached Files Attached Files

  5. #5
    Forum Expert Palmetto's Avatar
    Join Date
    04-04-2007
    Location
    South Eastern, USA
    MS-Off Ver
    XP, 2007, 2010
    Posts
    3,978

    Re: Using Check Box To Delete Row

    You have the code in a standard module.
    It must reside in the sheet module. In your case, sheet1 which is listed in the VBA project Window.
    Cut or copy the code from the standard module, activate the sheet module then paste it in.

  6. #6
    Registered User
    Join Date
    12-19-2008
    Location
    Boston
    Posts
    7

    Re: Using Check Box To Delete Row

    I removed all modules. I then clicked on "Sheet 1 (Summ-GM)" in the project view and pasted the code you provided. Now it only appears under that sheet. I'm still consfused as to how to make it runable. Thanks for your patience. I'm terrible with code.

    -Mark

  7. #7
    Forum Expert Palmetto's Avatar
    Join Date
    04-04-2007
    Location
    South Eastern, USA
    MS-Off Ver
    XP, 2007, 2010
    Posts
    3,978

    Re: Using Check Box To Delete Row

    See attached. All is working.
    Attached Files Attached Files

  8. #8
    Registered User
    Join Date
    12-19-2008
    Location
    Boston
    Posts
    7

    Re: Using Check Box To Delete Row

    When I click on any empty cell it is deleting the whole row. Checkboxed ones remain.

  9. #9
    Forum Expert Palmetto's Avatar
    Join Date
    04-04-2007
    Location
    South Eastern, USA
    MS-Off Ver
    XP, 2007, 2010
    Posts
    3,978

    Re: Using Check Box To Delete Row

    When I click on any empty cell it is deleting the whole row. Checkboxed ones remain.
    Disable macros when opening the workbook, manually delete the check marks, save and close the file then re-open it and it will function correctly.

    The code is designed to simultaneously enter a check mark and immediately delete the row.

    If you want to place a check mark into cell and then delete the rows all at once after making all selections rather than delete them "as you go" then see the attached workbook.

    It uses a separate macro assigned to a button and will delete checked rows on demand.
    Attached Files Attached Files

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

    Re: Using Check Box To Delete Row

    Quote Originally Posted by Palmetto
    Disable macros when opening the workbook, manually delete the check marks, save and close the file then re-open it and it will function correctly.
    You can disable and re-enable macros from within the workbook itself, you don't have to close and open with macros disabled completely.

    Just click the DESIGN MODE icon on the Control Toolbox toolbar to disable the macros temporarily, then click it again to turn them back on.
    _________________
    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!)

+ 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