TechWhirl (TECHWR-L) is a resource for technical writing and technical communications professionals of all experience levels and in all industries to share their experiences and acquire information.
For two decades, technical communicators have turned to TechWhirl to ask and answer questions about the always-changing world of technical communications, such as tools, skills, career paths, methodologies, and emerging industries. The TechWhirl Archives and magazine, created for, by and about technical writers, offer a wealth of knowledge to everyone with an interest in any aspect of technical communications.
Subject:RE: Delete cell from table in Word? - Macro From:"Chinell, David F (GE Indust, Security)" <David -dot- Chinell -at- GE -dot- com> To:"TECHWR-L" <techwr-l -at- lists -dot- techwr-l -dot- com> Date:Wed, 20 Jun 2007 18:29:59 -0400
Okay, here are some rough-n-ready macros to do the cell shuffle. I don't
know if this is the best way to get the selected cell's index etc. I go
ahead and add a row just in case, then delete it at the end if it's
empty.
I was startled to discover that the same row-test-and-delete routine
worked for both insertion and deletion routines.
It may be possible to express this as a function and combine the code.
But probably just as easy to assign them to separate commands or
keystrokes or buttons.
Sub CellInsert()
Dim objCell As Cell
Dim objRange As Range
Dim lngCount As Long
Dim lngIndex As Long
Dim I As Integer
Dim flgEmpty As Boolean
Application.ScreenUpdating = False
' Determine the selected cell's index
Set objRange = Selection.Tables(1).Range
objRange.End = Selection.Cells(1).Range.End
lngIndex = objRange.Cells.Count
' Determine the original cell count
lngCount = Selection.Tables(1).Range.Cells.Count
' Insert a row at the end of the table
Selection.Tables(1).Rows.Add
' Move downstream cells to the right
For I = lngCount To lngIndex Step -1
Selection.Tables(1).Range.Cells(I).Range.Cut
Selection.Tables(1).Range.Cells(I + 1).Range.Paste
Next I
' Delete the last row if empty
flgEmpty = True
Set objRange = Selection.Tables(1).Rows.Last.Range
For I = 1 To objRange.Cells.Count
If objRange.Cells(I).Range.Characters.Count > 2 Then
flgEmpty = False
End If
Next I
If flgEmpty = True Then
Selection.Tables(1).Rows.Last.Delete
End If
' Cleanup
Set objCell = Nothing
Set objRange = Nothing
Application.ScreenUpdating = True
End Sub
Sub CellDelete()
Dim objCell As Cell
Dim objRange As Range
Dim lngCount As Long
Dim lngIndex As Long
Dim I As Integer
Dim flgEmpty As Boolean
Application.ScreenUpdating = False
' Determine the selected cell's index
Set objRange = Selection.Tables(1).Range
objRange.End = Selection.Cells(1).Range.End
lngIndex = objRange.Cells.Count
' Determine the original cell count
lngCount = Selection.Tables(1).Range.Cells.Count
' Delete the selected cell
Selection.Cells(1).Range.Delete
' Move downstream cells to the left
For I = lngIndex + 1 To lngCount
Selection.Tables(1).Range.Cells(I).Range.Cut
Selection.Tables(1).Range.Cells(I - 1).Range.Paste
Next I
' Delete the last row if empty
flgEmpty = True
Set objRange = Selection.Tables(1).Rows.Last.Range
For I = 1 To objRange.Cells.Count
If objRange.Cells(I).Range.Characters.Count > 2 Then
flgEmpty = False
End If
Next I
If flgEmpty = True Then
Selection.Tables(1).Rows.Last.Delete
End If
' Cleanup
Set objCell = Nothing
Set objRange = Nothing
Application.ScreenUpdating = True
End Sub
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Create HTML or Microsoft Word content and convert to Help file formats or
printed documentation. Features include support for Windows Vista & 2007
Microsoft Office, team authoring, plus more. http://www.DocToHelp.com/TechwrlList
True single source, conditional content, PDF export, modular help.
Help & Manual is the most powerful authoring tool for technical
documentation. Boost your productivity! http://www.helpandmanual.com
---
You are currently subscribed to TECHWR-L as archive -at- web -dot- techwr-l -dot- com -dot-