【发布时间】:2014-12-20 06:10:47
【问题描述】:
我正在尝试创建两个数组:一个具有橙色单元格的行号,另一个具有蓝色单元格的行号。我一直在尝试调试这段代码,但它给了我错误:“编译错误:需要对象”;同时以黄色突出显示函数的第一行:“Function ArrayOrangeBlue()”。我是 VBA 的新手,我很确定我在语法中遗漏了一些东西。
请问您有什么意见吗?
Sub CommandButton1_Clicked()
ArrayOrangeBlue
End Sub
Function ArrayOrangeBlue()
Dim i As Integer 'row number'
Dim j As Integer 'orange counter'
Dim k As Integer 'blue counter'
Dim l As Integer
Dim m As Integer
Dim blue(1 To 1000) As Double
Dim orange(1 To 1000) As Double
'Starting Row'
Set i = 10
'Initialize orange and blue counters to 1'
Set j = 1
Set k = 1
Set l = 10
Set m = 10
'Loop until Row 1000'
Do While i <= 1000
'Dim cell As Range
'Set cell = ActiveSheet.Cells(i, 1)
'If cell colour is Orange- note absolute row number (i) in array: orange'
If Cells(i, 1).Interior.Color = 9420794 Then
orange(j) = i
Sheets("Detail analysis").Cells(l, 15) = i
j = j + 1
l = l + 1
'MsgBox ("This one is Orange")
Else
'If cell colour is Blue- note absolute row number (i) in array: blue'
If Cells(i, 1).Interior.Color = 13995347 Then
blue(k) = i
Sheets("Detail analysis").Cells(m, 16) = i
k = k + 1
m = m + 1
'MsgBox ("This one is Blue")
End If
End If
i = i + 1
Loop
End Function
【问题讨论】:
-
从包含变量赋值行的行中省略
set,例如set j=1
标签: vba colors conditional-statements do-while