Logo 
Search:

MS Office Forum

Ask Question   UnAnswered
Home » Forum » MS Office       RSS Feeds

VBA ThisWorkbook.Worksheets gives error in middle of process

  Asked By: Michael    Date: Mar 27    Category: MS Office    Views: 1839
  

This code works for the first several worksheets, then gives me a error: "Run Time Error 1004 Select Method of
Worksheet Class failed". There are 25 sheets to erase (plus the 2 it ignores). This same VBA works on another workbook just fine. HINT: I tried moving the position of the tab it stops at to the left in the order of tabs on the bottom of the workbook, but it then gives the error one file sooner. You will probably tell I'm no expert on VBA by my code, so if you have an idea for me, please be real basic in your suggestion :) Thanks!

For Each xsheet In ThisWorkbook.Worksheets
If xsheet.Name <> "Input" Then
If xsheet.Name <> "Mkt" Then

xsheet.Select

' clear_CONDITIONAL Formatting

Columns("A:K").Select
Selection.FormatConditions.Delete

' Erase workseet

Range("A6:M250").Select
Selection.ClearContents
'
Columns("A:M").Select
Range("A2").Activate
Selection.ClearContents
With Selection.Interior
.Pattern = xlNone
.TintAndShade = 0
.PatternTintAndShade = 0
End With
Selection.Borders(xlDiagonalDown).LineStyle = xlNone
Selection.Borders(xlDiagonalUp).LineStyle = xlNone
Selection.Borders(xlEdgeLeft).LineStyle = xlNone
Selection.Borders(xlEdgeTop).LineStyle = xlNone
Selection.Borders(xlEdgeBottom).LineStyle = xlNone
Selection.Borders(xlEdgeRight).LineStyle = xlNone
Selection.Borders(xlInsideVertical).LineStyle = xlNone
Selection.Borders(xlInsideHorizontal).LineStyle = xlNone
Range("b1").Select

' type into cell
ActiveCell.FormulaR1C1 = "<-- Ctrl+Shift+P to paste into A1"

Range("A1").Select

End If
End If


Next xsheet

Share: 

 

No Answers Found. Be the First, To Post Answer.

 




Tagged: