我正在尝试遍历一个大型列表行,根据另一个选项卡中的值搜索特定列的值。我让它为一个值工作,但是一旦我添加第二个标准,我就会收到关于“Set TwoRange = Application.Union(TwoRange, cell.EntireRow)”的错误。我在下面输入了我的代码。
有人知道我为什么会收到这些错误吗?
编辑:错误是“运行时错误'5':无效的过程调用或参数
Sub Calculate()
'----Data Pull----'
Dim cell As Range
Dim OneRange As Range
Dim TwoRange As Range
Dim ThreeRange As Range
Dim FourRange As Range
Dim FiveRange As Range
Dim SixRange As Range
Dim SevenRange As Range
Dim EightRange As Range
Dim NineRange As Range
Dim TenRange As Range
Dim MyCount As Long
Dim ExistCount As Long
ExistCount = 0
MyCount = 1
For Each cell In Worksheets("Data").Range("C2:C99999")
If cell.Value = Worksheets("Calculation").Range("B8").Value Then
ExistCount = ExistCount + 1
If MyCount = 1 Then Set OneRange = cell.Offset(0, -1)
Set OneRange = Application.Union(OneRange, cell.EntireRow)
MyCount = MyCount + 1
ElseIf cell.Value = Worksheets("Calculation").Range("B9").Value Then
ExistCount = ExistCount + 1
If MyCount = 1 Then Set TwoRange = cell.Offset(0, -1)
Set TwoRange = Application.Union(TwoRange, cell.EntireRow)
MyCount = MyCount + 1
End If
Next cell
If ExistCount > 0 Then
OneRange.Copy Destination:=Worksheets("LOB One").Range("A3")
End If
If ExistCount > 0 Then
TwoRange.Copy Destination:=Worksheets("LOB Two").Range("A3")
End If
End Sub