我有一个工作簿与多个工作表。间歇性错误:对象不支持此属性或方法
Private Sub CommandButton1_Click()
Call PivotColor(Sheet3, "1Up", "1Down", 30, 6)
End Sub
,并在此他的功能“PivotColor”后面的代码:
Sub PivotColor(Sheetname As Worksheet, UpArrow As String, DownArrrow As String, Columnreference As Integer, Rowreference As Integer)
If (Sheetname.Cells(Rowreference, Columnreference) >= 0) Then
' Select RED Arrow
Sheetname.Shapes.Range(Array(DownArrrow)).Select
' Hide the Red Arrow
With Selection.ShapeRange.Fill
.Visible = msoTrue
.Transparency = 1
.Solid
End With
' Otherwise it means the value of the cells is negative...
Else
' Select RED Arrow
Sheetname.Shapes.Range(Array(DownArrrow)).Select
' Display the Red Arrow
With Selection.ShapeRange.Fill
.Visible = msoTrue
.Transparency = 0
.Solid
End With
End If
End Sub
在Sheet3中我使用按钮1时,有一个按钮(名为Button1),这是用来运行下面的代码工作良好
现在,如果我在第二个工作表(名为sheet2)中创建一个新按钮(名为button2)并将相同的代码关联到该工具,则会出现错误“对象不支持此属性或方法”。
Private Sub CommandButton2_Click()
Call PivotColor(Sheet3, "1Up", "1Down", 30, 6)
End Sub
如果我点击“调试”,它强调了这一行:
With Selection.ShapeRange.Fill
所以基本上,这里的想法是要执行应该发生在工作表Sheet 3的过程,但是从Sheet2中启动它。
我不明白它不起作用...任何想法?
当您点击调试时,您能看到是否选择了向下箭头吗?它被选中了吗? – HarveyFrench
我认为它被选为“调试”按钮突出显示[Sheetname.Shapes.Range(Array(DownArrrow))之后的下一个代码行。 – SkorPPio