excel - VBA 合并单元格的大小必须相同
问题描述
我有以下代码在电子表格中对数据、任务列表进行排序,首先它按任务优先级排序,将“已完成”推到底部,然后按日期排序,不包括已完成任务的任务;
Sub mcr_PushDown_Completed_Taks()
'
' Push down completed tasks
'
'Turn off screen updating so macro working/flashing does not show
Application.ScreenUpdating = False
With Worksheets("Tasks")
With .Range(.Cells(7, "A"), .Cells(.Rows.Count, "A").End(xlUp).Offset(0, 10))
.Cells.Sort Key1:=.Columns(1), Order1:=xlAscending, _
Orientation:=xlTopToBottom, Header:=xlYes
With .Resize(Application.Match(7, .Columns(1), 0) - 1, .Columns.Count)
.Cells.Sort Key1:=.Columns(2), Order1:=xlDescending, _
Orientation:=xlTopToBottom, Header:=xlYes
End With
End With
End With
Range("B7").Select
End Sub
但是,当我运行宏时突然出现错误
为此,所有合并的单元格必须具有相同的大小。
但是,我无法使用“查找”对话框在工作表上找到任何合并的单元格。我还能如何找到合并的单元格或解决这个问题?
解决方案
这个子将找到合并的单元格。它使用 . MergeArea
查找合并单元格时的范围属性。VBA 不提供一个单元格属性,该属性会返回一个简单的“TRUE”到问题“我是合并区域的一部分”,因此如果单元格的区域与常规单元格相同,您需要自行评估或者如果它是更大区域的一部分。
Sub FindMergedCells()
Dim Rng As Range
Dim c As Range
Set Rng = Selection
With Rng
For Each c In Rng
If Not (c.MergeArea.Address = c.Address) Then
Debug.Print c.Address & " is a merged cell"
End If
Next c
End With
End Sub
推荐阅读
- ios - UIView 和 UICollection 的动态约束
- javascript - JS TypeError: texte is null - 如何从不为 null 的 textarea 开始?
- github - githubActions:如何显示测试覆盖率?
- python - 用 Keras 计数
- javascript - 分块运行 HTTP 请求
- python - 遍历字典值以形成 URL
- java - 我有一个错误,我陷入了他的错误:E/RecyclerView:没有连接适配器;跳过布局
- python - 如何使用基于规则的任务生成器目标在 Waf 的源目录中输出?
- flutter - 从firebase中的文档获取子集合的颤振问题
- c# - 如何为复杂的 Json 有效负载设置属性及其值并进行序列化?