-
Wow.
1. Thanks Gerry. Your explanation made a lot of sense. I like this line: "Since VBA has no idea either, it shrugs and simply refuses to deal with them." I was really struggling conceptually with how to deal with something that can't iterate the way I'm used to.
2. Thanks Tony. Your code works beautifully. It'll probably take me a little bit to fully understand the logic behind it, but it looks great.
Here's something I added:
The data "sections" were separated by an entire row of blank cells, basically just to break up the data. In order to preserve these breaks, I looped through all the rows and checked the value of a cell that would only be blank if the entire row were blank. I then set the text value for each of the cells in that row to be something (like "___"). I think this might be called something, like dummy variables or something. Then at the end it does a find & replace for that value, replacing "___" with "".
Here's the final code for others to see:
[VBA]Sub MergeBlankCells()
Dim CurrentCell As Word.Cell
Dim TextCell As Word.Cell, LastEmptyCell As Word.Cell
Dim oRow As Row
For Each oRow In ActiveDocument.Range.Tables(1).Rows
If oRow.Cells(4).Range.Text = Chr(13) & Chr(7) Then
For i = 1 To 8
oRow.Cells(i).Range.Text = "___"
Next i
End If
Next
For Each CurrentCell In ActiveDocument.Range.Tables(1).Columns(3).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
ActiveDocument.Tables(1).Select
With Selection.Find
.Text = "___"
.Replacement.Text = ""
.Forward = True
.Wrap = wdFindContinue
.Format = False
.MatchCase = False
.MatchWholeWord = False
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
End With
Selection.Find.Execute Replace:=wdReplaceAll
End Sub[/VBA]
I thank you both - the help and advice you've offered was very informative and I really appreciate it.
Cheers
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules