调用MergeArea时无效的过程调用或参数

时间:2017-05-23 14:09:28

标签: vba excel-vba excel

我有一个子查找空单元格,如果单元格不为空,则检查合并的单元格是否为空。只有在知道String为真后才会调用MergeArea。所以我不知道为什么会有这个错误。此错误取决于范围 - 如果范围内没有合并的单元格,则可以正常运行。

MergeCells

1 个答案:

答案 0 :(得分:0)

cell.MergeArea(Cells(1, 1))不会为您提供MergeArea中的第一个单元格。更改以下内容:

With cell.MergeArea
    Set cellFirst = cell.MergeArea(Cells(1, 1))
    If IsEmpty(cellFirst) Then
        k = k + 1
    End If
End With

为:

With cell.MergeArea
    Set cellFirst = .Cells(1, 1)
    If IsEmpty(cellFirst) Then
        k = k + 1
    End If
End With

或者你可以取消WithEnd WithSet范围,只需使用

If IsEmpty(cell.MergeArea.Cells(1, 1)) Then
    k = k + 1
End If