azexceluser
New Member
- Joined
- Jan 14, 2016
- Messages
- 2
I am using the following code to delete the header from each worksheet in a large Excel workbook. The code is running fine until it gets to one specific worksheet, then I receive the following error message: "Run-time error '1004': Select method of worksheet class failed". I have inserted this code into other workbooks as a test, and I do not get the error, so it is something specific about this one worksheet within this one particular workbook. I have also tried deleting the code, doing a "save as" on the workbook and starting over, but the error continues to occur. Following is the code I am using, I have changed the problem area to red:
Any ideas or suggestions would be appreciated!
Rich (BB code):
Private Sub CommandButton1_Click()
'Variable Declaration
Dim cnt As Integer
Dim i As Integer
'Assign Variables
cnt = ActiveWorkbook.Worksheets.Count - 1
'Remove Headers
Application.ScreenUpdating = False
For i = 2 To cnt
Worksheets(i).Select
With ActiveSheet.PageSetup
.LeftHeader = ""
.CenterHeader = ""
.RightHeader = ""
End With
Next i
Application.ScreenUpdating = True
End Sub
Any ideas or suggestions would be appreciated!