简体   繁体   English

在Excel中创建工作表的列表对象

[英]Create a list object of sheets in excel

I want to run a for loop in vba which contain some of the sheets of the workbook,not all. 我想在vba中运行一个for循环,其中包含工作簿的某些工作表,而不是全部。 So, for that I don't know how to create a list object. 因此,为此,我不知道如何创建列表对象。 I am able to loop across all the sheets in the workbook using this the following code but I don't how to select some particular sheets. 我可以使用以下代码在工作簿中的所有工作表之间循环,但是我不选择某些特定工作表。

For Each ws In Worksheets

How about something like this, where you create an array. 这样的事情怎么样,在这里创建一个数组。 Excel VBA has a limited number of data structures that you can use. Excel VBA可以使用的数据结构数量有限。 An Array is the most common that suits your needs. 阵列是最适合您需求的阵列。 You declare the array then loop through it. 您声明数组,然后遍历它。 The below is a simple example that solves your problem. 以下是解决您的问题的简单示例。

Sub SelectSheet()

Dim SheetList(1 To 3) As String

SheetList(1) = "Sheet1"
SheetList(2) = "Sheet3"
SheetList(3) = "Sheet6"


For i = 1 To 3
    Sheets(SheetList(i)).Select
    Range("C3").FormulaR1C1 = "Here"

Next i

End Sub

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM