我对ms字表有疑问。
如何用for循环合并“ ok”之前的空单元格,然后用文本“ waiting list”替换空单元格,
样本:
#before:
空
空
好
空
空
空
好
空
好
#之后:
等待名单
好
等待名单
好
等待名单
好
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
谢谢
答案 0 :(得分:0)
尝试一下,让我知道它的进展,
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).Range.Text = Chr(13) & Chr(7) And .Cell(i + 1, 1).Range.Text = Chr(13) & Chr(7) Then
On Error Resume Next
.Cell(Row:=i, Column:=1).Merge MergeTo:=.Cell(Row:=i + 1, Column:=1)
On Error GoTo 0
i = i - 1
If i = ActiveDocument.Tables(1).Rows.Count - 1 Then
GoTo EnterText
End If
End If
End With
Next i
EnterText:
x = ActiveDocument.Tables(1).Rows.Count
For i = 1 To x
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