ilikered100
New Member
- Joined
- May 29, 2013
- Messages
- 46
I'm sure I am missing something very simple, but I cannot get this code to work properly.
For the purpose of this example, let's say I have a workbook with 10 worksheets, each worksheet named with a different color. I want to use an array of three worksheet names ("Red", "Blue" , "Green") and clear the contents of only those three sheets. When I run the code below, whatever worksheet I'm on (whether in the array or not), the code runs three times on that sheet only. It only clears the content on the worksheet I am currently on.... again whether that worksheet is one of the three in the array or not. I've tried many variations of the below without success.
Any help is appreciated.
Carolyn
For the purpose of this example, let's say I have a workbook with 10 worksheets, each worksheet named with a different color. I want to use an array of three worksheet names ("Red", "Blue" , "Green") and clear the contents of only those three sheets. When I run the code below, whatever worksheet I'm on (whether in the array or not), the code runs three times on that sheet only. It only clears the content on the worksheet I am currently on.... again whether that worksheet is one of the three in the array or not. I've tried many variations of the below without success.
Sub ClearSpecificSheets()
Dim ws As Worksheet
Dim arrListofSheets As Variant
Set arrListofSheets = ActiveWorkbook.Sheets(Array("Red", "Blue", "Green"))
For Each ws In arrListofSheets
Cells.Select
Selection.ClearContents
Next ws
End Sub
Any help is appreciated.
Carolyn