Kilroy
07-28-2016, 04:35 AM
I've discovered an issue with this code. It was exactly what I asked for but I've run into a scenario where it doesn't work. It looks at a cell and if it's empty it merges with the first cell above it that has a "character" in it. What's happen is that when it runs it is merging into the column header. I've tried changing character to number but it doesn't work. How do I change it so that it will only merge with the first cell above that has a number? I'm running a macro before this one that formats numbering to text but I still need it to only merge with a cell that has a number.
Sub mergeemptycellwithabovecellwithtext()
Dim CurrentCell As Word.Cell
Dim TextCell As Word.Cell, LastEmptyCell As Word.Cell
For Each CurrentCell In ActiveDocument.Range.Tables(1).Columns(1).Cells
If CurrentCell.Range.Characters.Count > 1 Then
If Not TextCell Is Nothing And Not LastEmptyCell Is Nothing Then
TextCell.Merge LastEmptyCell
End If
Set LastEmptyCell = Nothing
Set TextCell = CurrentCell
Else
Set LastEmptyCell = CurrentCell
End If
Next
If Not TextCell Is Nothing And Not LastEmptyCell Is Nothing Then
TextCell.Merge LastEmptyCell
End If
End Sub
Sub mergeemptycellwithabovecellwithtext()
Dim CurrentCell As Word.Cell
Dim TextCell As Word.Cell, LastEmptyCell As Word.Cell
For Each CurrentCell In ActiveDocument.Range.Tables(1).Columns(1).Cells
If CurrentCell.Range.Characters.Count > 1 Then
If Not TextCell Is Nothing And Not LastEmptyCell Is Nothing Then
TextCell.Merge LastEmptyCell
End If
Set LastEmptyCell = Nothing
Set TextCell = CurrentCell
Else
Set LastEmptyCell = CurrentCell
End If
Next
If Not TextCell Is Nothing And Not LastEmptyCell Is Nothing Then
TextCell.Merge LastEmptyCell
End If
End Sub