View Single Post
  #3   Report Post  
Posted to microsoft.public.excel.misc
OssieMac OssieMac is offline
external usenet poster
 
Posts: 2,510
Default Combining macros

The CodeName for a worksheet does not change when you change the sheet name
on the sheet tab.
To see the code names, in the VBA editor on the Project Explorer, the code
name is first and the given sheet name is in parenthesis. Before renaming any
sheet they are the same but after renaming the Code name remains unchanged.

Try the following method. I have used Select Case because it is so easy to
alter the CodeNames. Check your actual codenames agains the given names to
ensure you have them correct.

NOTE: A soace and underscoire at the end of a line is a line break in an
otherwise single line of code.

Public Sub ClearRangeIn12Sheets()
Const csCellRef As String = "A2:I7"
Dim ws As Worksheet
For Each ws In Worksheets
Select Case ws.CodeName
Case "Sheet1", "Sheet2", "Sheet3", _
"Sheet4", "Sheet5", "Sheet6", _
"Sheet7", "Sheet8", "Sheet9", _
"Sheet10", "Sheet11", "Sheet12"
ws.Range(csCellRef).ClearContents
End Select
Next ws
End Sub


--
Regards,

OssieMac