I want to preform certain code on designated worksheets in my workbook. I only want to do this code for some of the worksheets, but not all of them.
What I would like to do is the following:
For Each ws in ActiveWorkBook.Worksheets
'do some code
Next ws
Since I only want to run the code within the for loop for certain worksheets, I don't know how to replace 'ActiveWorkBook.Worksheets' with another variable that will hold the worksheet objects/names.
I've tried this:
Dim arrayone as variant
arrayone = array("worksheetname1", "worksheetname4")
I then used the arrayone variable in the for loop but this doesn't seem to work. I get an object required error.
I may not be understanding when I should reference an object or the sheetnames.
Does anyone know how I can reference some of the worksheets, but not all of them, in VBA code?
What I would like to do is the following:
For Each ws in ActiveWorkBook.Worksheets
'do some code
Next ws
Since I only want to run the code within the for loop for certain worksheets, I don't know how to replace 'ActiveWorkBook.Worksheets' with another variable that will hold the worksheet objects/names.
I've tried this:
Dim arrayone as variant
arrayone = array("worksheetname1", "worksheetname4")
I then used the arrayone variable in the for loop but this doesn't seem to work. I get an object required error.
I may not be understanding when I should reference an object or the sheetnames.
Does anyone know how I can reference some of the worksheets, but not all of them, in VBA code?
Last edited: