【发布时间】:2021-03-16 15:53:44
【问题描述】:
我在 VBA 中有一些代码,它试图根据活动工作表的特定列中的值对行进行分组。我看到的问题是在线If rngArea Is Nothing Then 它给了我
424:需要对象
错误。
我想我已经正确地将rngArea 变量声明为Range,如果这个变量最初是空的,那么Is Nothing 是正确的,对吧?这么简单的一行代码,我看不出还有什么问题。
有人可以帮忙吗?
Sub GroupEpics()
FTESheet.Activate
Dim c, rngArea, EpicLink As Range
LstRow = FTESheet.Cells(Rows.Count, "B").End(xlUp).Row
Set EpicLink = FTESheet.Range(Cells(3, 4), Cells(LstRow, 4))
'undo any existing groupings
'suppress error if no rows are grouped
On Error Resume Next
Range("A1:A" & LstRow).Rows.Ungroup
On Error GoTo 0
'loop through all epic link values
For Each c In EpicLink
If c.Value <> 0 And c.Row() > 2 Then
'add this epic row to the cumulative range
If rngArea Is Nothing Then
Set rngArea = c
Else
Set rngArea = Union(rngArea, c)
End If
End If
Next c
' loop through Range's Areas and group each one of them
For Each c In rngArea.Areas
c.EntireRow.Group
Next c
End Sub
【问题讨论】: