Reputation: 125
I want to run a for loop in vba which contain some of the sheets of the workbook,not all. 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
Upvotes: 0
Views: 1018
Reputation: 710
How about something like this, where you create an array. Excel VBA has a limited number of data structures that you can use. 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
Upvotes: 2