Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 04-20-2016, 05:32 AM
daveydave daveydave is offline How to delete user input row and re-number column Windows 10 How to delete user input row and re-number column Office 2016
Novice
How to delete user input row and re-number column
 
Join Date: Apr 2016
Posts: 3
daveydave is on a distinguished road
Default How to delete user input row and re-number column


I have a table in a word document that I need to delete a specific row from. The user would input the row number they would want to delete and once the row is deleted then the row numbers in the column would re-number appropriately 1, 2, 3, 4, etc. The user would also not be able to delete the last row and the user would receive an error message if a row did not exist. I have been struggling with this for awhile and now I need to call in the big guns. Thanks in advance!
Reply With Quote
  #2  
Old 04-20-2016, 06:50 AM
macropod's Avatar
macropod macropod is offline How to delete user input row and re-number column Windows 7 64bit How to delete user input row and re-number column Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 22,340
macropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond repute
Default

Why not simply auto-number the rows and let the user select & delete the row?
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
  #3  
Old 04-20-2016, 06:57 AM
daveydave daveydave is offline How to delete user input row and re-number column Windows 10 How to delete user input row and re-number column Office 2016
Novice
How to delete user input row and re-number column
 
Join Date: Apr 2016
Posts: 3
daveydave is on a distinguished road
Default

Thanks for the reply. I have the content control locked and I believe it is causing the table to be locked for editing. Right clicking the row the option to delete the row is greyed out. I love the idea of having a non VBA solution.
Reply With Quote
  #4  
Old 04-20-2016, 03:30 PM
gmaxey gmaxey is offline How to delete user input row and re-number column Windows 7 32bit How to delete user input row and re-number column Office 2010 (Version 14.0)
Expert
 
Join Date: May 2010
Location: Brasstown, NC
Posts: 1,598
gmaxey is just really nicegmaxey is just really nicegmaxey is just really nicegmaxey is just really nicegmaxey is just really nice
Default

Sub ScratchMacro()
'A basic Word macro coded by Greg Maxey
Dim oTbl As Table
Dim lngRow As Long
Dim oCC As ContentControl
Set oTbl = ActiveDocument.Tables(1)
lngRow = CLng(InputBox("What row?"))
For Each oCC In oTbl.Rows(lngRow).Range.ContentControls
oCC.LockContentControl = False
oCC.LockContents = False
Next
oTbl.Rows(lngRow).Delete
oTbl.Range.Fields.Update 'I assume you have numbered the rows with a Seq Field.
lbl_Exit:
Exit Sub
End Sub
__________________
Greg Maxey
Please visit my web site at http://www.gregmaxey.com/
Reply With Quote
  #5  
Old 04-20-2016, 05:58 PM
macropod's Avatar
macropod macropod is offline How to delete user input row and re-number column Windows 7 64bit How to delete user input row and re-number column Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 22,340
macropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond repute
Default

I wasn't aware from your previous post that the content control was locked. Even then, it requires nothing more than unlocking it, which could be expedited with a macro like:
Code:
Sub Demo()
Dim CCtrl As ContentControl
With Selection
  If .Information(wdWithInTable) = False Then Exit Sub
  With .Rows(1)
    For Each CCtrl In .Range.ContentControls
      CCtrl.LockContentControl = False
      CCtrl.LockContents = False
    Next
    .Delete
  End With
End With
End Sub
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
  #6  
Old 04-22-2016, 09:39 AM
daveydave daveydave is offline How to delete user input row and re-number column Windows 10 How to delete user input row and re-number column Office 2016
Novice
How to delete user input row and re-number column
 
Join Date: Apr 2016
Posts: 3
daveydave is on a distinguished road
Default

Yeah sorry about that I should have clarified.

Greg's solution worked like a champ.

How about an error message if the row doesn't exist or it is the last row?
Reply With Quote
  #7  
Old 04-22-2016, 12:17 PM
gmaxey gmaxey is offline How to delete user input row and re-number column Windows 7 32bit How to delete user input row and re-number column Office 2010 (Version 14.0)
Expert
 
Join Date: May 2010
Location: Brasstown, NC
Posts: 1,598
gmaxey is just really nicegmaxey is just really nicegmaxey is just really nicegmaxey is just really nicegmaxey is just really nice
Default

How about what have you tried?
__________________
Greg Maxey
Please visit my web site at http://www.gregmaxey.com/
Reply With Quote
Reply



Similar Threads
Thread Thread Starter Forum Replies Last Post
User input box with IF statement ChrisJ83 Word VBA 9 11-13-2015 06:20 PM
Variable arrays from user input SeattleITguy Excel Programming 1 01-29-2015 09:19 AM
How to delete user input row and re-number column vba: user input named argument andrew12345 Excel Programming 2 11-18-2014 08:18 AM
How to delete user input row and re-number column User input to a variable on the document dsm1995gst Word VBA 1 09-03-2013 03:43 PM
How to delete user input row and re-number column Replacing text with user input.?.?.? brad1977 Word 3 11-20-2012 10:20 AM

Other Forums: Access Forums

All times are GMT -7. The time now is 12:30 PM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2025, vBulletin Solutions Inc.
Search Engine Optimisation provided by DragonByte SEO (Lite) - vBulletin Mods & Addons Copyright © 2025 DragonByte Technologies Ltd.
MSOfficeForums.com is not affiliated with Microsoft