如何根据单元格内部的信息制作变量数组?

时间:2019-04-02 20:55:31

标签: excel vba

我正在尝试根据是否单击复选框来列出要隐藏或取消隐藏的工作表列表。我想要一个包含一系列单元格的工作表的列表,但是我的功能无法正常工作。我以为是因为它被认为是字符串,所以我称之为某种东西。

With Worksheets("Home Page").Cells
    Set findSheets = .Find(What:="Sheets", LookIn:=xlValues)
End With

findSheets.Select
Selection.Offset(2, 0).Select
num = 1

ArrayList = Chr(34) & Selection.Value & Chr(34)
Selection.Offset(1, 0).Select

For Each MyCell In Range(Selection, Selection.End(xlDown))
    ArrayList = ArrayList & ", " & Chr(34) & Selection.Value & Chr(34)
    Selection.Offset(1, 0).Select
Next
ArrayList = ArrayList & ")"
ArrayList = Array(ArrayList)

If CheckBox1.Value = True Then
    Worksheets(Array(ArrayList)).Visible = True
Else
    Worksheets(Array(ArrayList)).Visible = False
End If

1 个答案:

答案 0 :(得分:0)

Dim shet
For Each shet In arraylist
    Worksheets(shet).Visible = CheckBox1.Value
Next shet