View Single Post
 
Old 09-08-2019, 08:53 AM
Iput Iput is offline Windows 10 Office 2007
Novice
 
Join Date: Sep 2019
Posts: 4
Iput is on a distinguished road
Default How to merge empty cells before "ok" with a for loop

I have the problem with ms word table. How to merge empty cells before "ok" with a for loop and then replace empty cell with text “waiting list”, sample :
#before :
empty
empty
ok
empty
empty
empty
ok
empty
ok

#After :
waiting list
ok
waiting list
ok
waiting list
ok
code :
Sub try()
Dim i As Integer, x As Integer, k As Integer
x = ActiveDocument.Tables(1).Rows.Count
'k = empty cell count before "ok"

For i = 1 To x - 1
With ActiveDocument.Tables(1)
If .Cell(i + 1, 1).Range.Text = Chr(13) & Chr(7) Then
.Cell(Row:=i, Column:=1).Merge MergeTo:=.Cell(Row:=i + k, Column:=1)
End If
End With
Next i

For i = 1 To x - 1
With ActiveDocument.Tables(1)
If .Cell(i, 1).Range.Text = Chr(13) & Chr(7) Then
.Cell(i, 1).Range.Text = “waiting list”
End If
End With
Next i

End Sub

thanks
Reply With Quote