VBA不允许我声明空的整数数组

时间:2016-08-08 22:50:30

标签: excel-vba vba excel

这段代码一直给我错误:" For Each只能迭代一个集合对象或数组。"当我将数组的类型更改为variant时,代码按预期工作,但我需要使用整数进行比较。有谁知道这里发生了什么?这段代码之前运行良好,但最近刚开始给我这个错误。

Sub Pulse_Pop_rColors()
'On Error GoTo Err
Dim lastC, lastR, n As Long
Dim findlcol As Range
Dim r, g, b, r1, g1, b1 As Integer
Dim arr() As Integer
ReDim arr(1 To 1) As Integer
With pop_frm
    r = .findR.Value
    g = .findG.Value
    b = .findB.Value
    r1 = .repR.Value
    g1 = .repG.Value
    b1 = .repB.Value
End With
lastR = Cells(Rows.Count, "A").End(xlUp).Row
Debug.Print "poop"
With ActiveSheet
    Set findlcol = .Columns(1).Find(What:="Column %", After:=.Cells(1, 1))
End With
n = findlcol.Row
lastC = Cells(n, Columns.Count).End(xlToLeft).Column
Debug.Print (lastC)
Debug.Print (lastR)
For ro = 1 To lastR
    If Cells(ro, 1).Interior.Color = RGB(r, g, b) Then
        Cells(ro, 1).Interior.Color = RGB(r1, g1, b1)
        arr(UBound(arr)) = ro
        ReDim Preserve arr(1 To UBound(arr) + 1) As Integer
        Debug.Print ro
    End If
Next ro
For Each x In arr(UBound(arr) - 1)
    If x > 0 Then
        Range(Cells(x, 2), Cells(x, lastC)).Interior.Color = RGB(r1, g1, b1)
    End If
Next x

0 个答案:

没有答案
相关问题