I'm trying to run a mailmerge and I want to delete all rows beside the header in each table if the last cell of that row is blank.
Here is the line I'm getting mismatch error:
If Split(.Cell(r, c).Range.Text, vbCr) = 0
Below is the sub:
Sub Delete_row_if_last_cell_is_blank()
Application.ScreenUpdating = False
Dim Tbl As Table, r As Long, c As Long
ActiveDocument.MailMerge.Execute
With ActiveDocument
For Each Tbl In .Tables
With Tbl
c = .Columns.Count
For r = .Rows.Count To 2 Step -1
If Split(.Cell(r, c).Range.Text, vbCr) = 0 Then .Rows(r).Delete
Next
End With
Next
End With
Application.ScreenUpdating = False
End Sub
I tried to put the result as empty or "" but it still doesn't work.
Split returns an array of the splitted items. Therefore instead of
use
which gives the array's top index value.