Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/vba/14.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/sql-server-2005/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Vba 如何在“之前合并空单元格”;“好的”;使用for循环_Vba_Ms Word - Fatal编程技术网

Vba 如何在“之前合并空单元格”;“好的”;使用for循环

Vba 如何在“之前合并空单元格”;“好的”;使用for循环,vba,ms-word,Vba,Ms Word,我有ms word表格的问题。 如何将“确定”之前的空单元格与for循环合并,然后将空单元格替换为文本“等待列表”, 样本: #之前: 空的 空的 嗯 空的 空的 空的 嗯 空的 嗯 #之后: 候补名单 嗯 候补名单 嗯 候补名单 嗯 谢谢试试这个,告诉我进展如何 Sub try() Dim i As Integer, x As Integer, k As Integer x = ActiveDocument.Tables(1).Rows.Count 'k = empty cell count

我有ms word表格的问题。 如何将“确定”之前的空单元格与for循环合并,然后将空单元格替换为文本“等待列表”, 样本:
#之前:
空的
空的

空的
空的
空的

空的


#之后:
候补名单

候补名单

候补名单


谢谢

试试这个,告诉我进展如何

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

谢谢,它可以工作,但是如果我尝试添加一列“name”,它就不起作用了,我会在if.Cell(I,1).Range.Text=Chr(13)&Chr(7)和.Cell(I+1,1).Range.Text=Chr(13)&Chr(7)中得到错误,你知道吗?你的意思是如果你在列中添加标题,你会得到错误?
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