ActiveSheet.Shapes.Range(Array("Rounded Rectangle 2")).Visible = Not ActiveSheet.Shapes.Range(Array("Rounded Rectangle 2")).Visible
ActiveSheet.Shapes.Range(Array("Rounded Rectangle 3")).Visible = Not ActiveSheet.Shapes.Range(Array("Rounded Rectangle 3")).Visible
ActiveSheet.Shapes.Range(Array("Rounded Rectangle 4")).Visible = Not ActiveSheet.Shapes.Range(Array("Rounded Rectangle 4")).Visible
ActiveSheet.Shapes.Range(Array("Rounded Rectangle 5")).Visible = Not ActiveSheet.Shapes.Range(Array("Rounded Rectangle 5")).Visible
这是我使用的代码宏示例
我想知道如何运行此代码以仅隐藏矩形1行
像
For i = 1 To ActiveSheet.Shapes.Count
ActiveSheet.Shapes.Range(Array("Rounded Rectangle *")).Visible = _
Not ActiveSheet.Shapes.Range(Array("Rounded Rectangle *")).Visible
Next i
我只是不知道如何正确简化
答案 0 :(得分:2)
离你不远,这是如何使用循环来完成所有Rounded Rectangles
Dim i As Long
For i = 1 To ActiveSheet.Shapes.Count
ActiveSheet.Shapes.Range(Array("Rounded Rectangle " & i)).Visible = _
Not ActiveSheet.Shapes.Range(Array("Rounded Rectangle " & i)).Visible
Next i
请注意"Rounded Rectangle " & i
如何替换为
"Rounded Rectangle 1"
"Rounded Rectangle 2"
"Rounded Rectangle n"
其中n = i
(表示循环运行的次数)
Rounded Rectangle 1
,请在循环中添加 If / else 语句
Rounded Rectangle 1
和切换。如果您想要始终显示它们,那么只需在else语句中指定 true
Dim i As Long
For i = 1 To ActiveSheet.Shapes.Count
If i = 1 Then
ActiveSheet.Shapes.Range(Array("Rounded Rectangle " & i)).Visible = False
Else
ActiveSheet.Shapes.Range(Array("Rounded Rectangle " & i)).Visible = _
ActiveSheet.Shapes.Range(Array("Rounded Rectangle " & i)).Visible
End If
Next i