VBA合并单元格/偏移量属性出现问题。我想浏览包含合并单元格的列表,并显示每个合并单元格的范围。
示例:
-
范围("A1"(。值为"A1";地址";
-
Range("A2:A50"(是一个合并的单元格;xyz@hotmail.com">
当我运行以下代码时:
- 问题1:范围("A1"(。值转换为"A1";xyz@hotmail.com">
- 问题2:偏移后,MergeArea.Address仍然返回Range("A1"(而不是Range("A2:A50"(
我的代码:
Sub Macro1()
Dim CellA As Range
Set CellA = Range("A1")
Do Until IsEmpty(CellA.Value) = True
If CellA.MergeCells = False Then
CellA = CellA.Offset(1, 0)
Else
CellA = CellA.Offset(1, 0)
MsgBox (CellA.MergeArea.Address)
End If
Loop
End
试试这个代码:
Sub Macro1()
Dim CellA As Range
Set CellA = Range("A1")
Do Until IsEmpty(CellA.Value) = True '
If CellA.MergeCells Then '
MsgBox CellA.MergeArea.Address
exit do
End If
Set CellA = CellA.Offset(1, 0)
Loop
End Sub