我是Excel宏的新手,我在编写这个用于编写宏的宏时遇到了一些麻烦。当我尝试运行此脚本时,出现“运行时错误'13'类型不匹配”错误。我要做的是让excel检查是一个单元格是黑色,然后如果是,让Excel将'myBit'中的相应数字添加到'ans',并在行的末尾,将列'J'设置为' ans'然后重复下一栏。很抱歉,如果你发现这令人困惑,但我尽力解释我想要做的事情。
Private Sub CommandButton1_Click()
Dim myRow
Dim myBit
Dim ans As Integer
Dim c As Integer
Dim r As Integer
myRow = Array("B", "C", "D", "E", "F", "G", "H", "I")
myBit = Array(128, 64, 32, 16, 8, 4, 2, 1)
c = 0
r = 3
For r = 3 To 11
ans = 0
For c = 0 To 8
If Cells(myRow(c) + r).Interior.Color = RGB(0, 0, 0) Then ans = ans + myBit(c)
Cells("J" + r).Value = ans
Next c
Next r
End Sub
答案 0 :(得分:7)
Cells(Row,Column)
的语法是Range
。请看这个
你需要Private Sub CommandButton1_Click()
Dim ans As Integer, c As Integer, r As Integer
Dim myRow, myBit
myRow = Array("B", "C", "D", "E", "F", "G", "H", "I")
myBit = Array(128, 64, 32, 16, 8, 4, 2, 1)
For r = 3 To 11
ans = 0
For c = 0 To 8
If Range(myRow(c) & r).Interior.Color = RGB(0, 0, 0) Then _
ans = ans + Val(myBit(c))
Range("J" & r).Value = ans
Next c
Next r
End Sub
而不是那个。也很少有东西是不需要的。这是你正在尝试的(未经过彻底测试)?
.