Microsoft Office Forums

Go Back   Microsoft Office Forums > Microsoft Word > Word Tables

Reply
 
LinkBack Thread Tools Display Modes
  #1  
Old 12-06-2017, 07:28 PM
baes10 baes10 is offline Windows 7 64bit Office 2007
Novice
 
Join Date: Dec 2017
Posts: 6
baes10 is on a distinguished road
Default Could you help me create a control button/check box to enable user to delete a row?

I have here a skin form i use to track wounds. I have now a macro to create a new row when needed. I need help creating a check box or a button next two each row to enable deletion of the entire row. Could you help? Thanks!
Attached Files
File Type: docm Skin Report.docm (88.2 KB, 3 views)
Reply With Quote
  #2  
Old 12-11-2017, 01:26 AM
gmayor's Avatar
gmayor gmayor is offline Windows 10 Office 2016
Expert
 
Join Date: Aug 2014
Posts: 2,227
gmayor is a jewel in the roughgmayor is a jewel in the roughgmayor is a jewel in the roughgmayor is a jewel in the rough
Default

As your form already contains code to add a row, then delete all the rows except the first to begin with and only add the rows as you require them, however to address your question the following will delete the row the cursor is in.

Code:
Sub DeleteTableRow()
Dim oCC As ContentControl
    If Selection.Information(wdWithInTable) = True Then
        For Each oCC In Selection.Rows(1).Range.ContentControls
            oCC.LockContentControl = False
            oCC.Delete
        Next oCC
        Selection.Rows(1).Delete
    Else
        MsgBox "Selection is not in a table!"
    End If
End Sub
__________________
Graham Mayor - MS MVP (Word)
Visit my web site for more programming tips and ready made processes www.gmayor.com
Reply With Quote
  #3  
Old 12-11-2017, 10:10 AM
baes10 baes10 is offline Windows 7 64bit Office 2007
Novice
 
Join Date: Dec 2017
Posts: 6
baes10 is on a distinguished road
Default

Quote:
Originally Posted by gmayor View Post
As your form already contains code to add a row, then delete all the rows except the first to begin with and only add the rows as you require them, however to address your question the following will delete the row the cursor is in.

Code:
Sub DeleteTableRow()
Dim oCC As ContentControl
    If Selection.Information(wdWithInTable) = True Then
        For Each oCC In Selection.Rows(1).Range.ContentControls
            oCC.LockContentControl = False
            oCC.Delete
        Next oCC
        Selection.Rows(1).Delete
    Else
        MsgBox "Selection is not in a table!"
    End If
End Sub
This is fantastic! May I ask one more question? I'd like to create a userform command button, to enable users to click and delete the rows as they wish in a protected form. None of the users will have a developer tool option. Basically, I need to make it as easy for the nurses to use as possible. Having the cursor in the row and being able to click the comman button to delete would be great. Hope this makes sense. Thank you!
Reply With Quote
Reply

Thread Tools
Display Modes


Similar Threads
Thread Thread Starter Forum Replies Last Post
how to get control/option-delete to only delete the word and not the preceding space microsofthelp Word 0 11-20-2016 04:34 AM
Force a user to enable macros in Powerpoint? Hide sheets until the "enable" button is clicked copleyr PowerPoint 1 10-07-2016 01:15 AM
Enable "check spelling as you type" for Form Fields zeroth Word 3 11-08-2012 08:57 AM
How do I enable a button in the quick access toolbar dpb001 Word VBA 1 05-02-2012 12:41 AM
issue in nested user control selva Misc 1 10-20-2011 10:18 PM


All times are GMT -7. The time now is 11:48 AM.


Powered by vBulletin® Version 3.8.1
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.
SEO by vBSEO ©2011, Crawlability, Inc.
MSOfficeForums.com is not affiliated with Microsoft