Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 192
  • Last Modified:

clear data of sheets except sheets named

Can someone provide me with VBA code that will clear all data off all sheets exc ept sheets names Sheet10 and Sheet 11

thank you
0
Jagwarman
Asked:
Jagwarman
  • 2
1 Solution
 
Shanan212Commented:
Sub SelectSheet() 
  Dim ws As Worksheet 
  For Each ws In Worksheeets 
 if  ws.name <> "Sheet10" and ws.name <> "Sheet11" then
    Cells.Select
    Selection.Clearcontents
end if
Next ws 

End Sub 

Open in new window

0
 
JagwarmanAuthor Commented:
I am getting 'Variable not defined' ???
0
 
Shanan212Commented:
Sub SelectSheet()
  Dim ws As Worksheet
  For Each ws In ActiveWorkbook.Worksheets

 If ws.Name <> "Sheet10" And ws.Name <> "Sheet11" Then
    Cells.Select
    Selection.ClearContents
    Range("A1").Select
End If
Next ws
MsgBox "Done!"

End Sub

Open in new window


Try this
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now