Solved

clear data of sheets except sheets named

Posted on 2013-01-31
3
174 Views
Last Modified: 2013-01-31
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
Comment
Question by:Jagwarman
  • 2
3 Comments
 
LVL 13

Expert Comment

by:Shanan212
ID: 38839845
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
 

Author Comment

by:Jagwarman
ID: 38839876
I am getting 'Variable not defined' ???
0
 
LVL 13

Accepted Solution

by:
Shanan212 earned 500 total points
ID: 38839924
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

How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

Join & Write a Comment

Problem: You created a new custom form in Outlook for your contacts (added fields, deleted fields, changed the layout of fields, whatever) and made it the default form for contacts. The good news is that all new contacts will utilize the new form. T…
This article will show you how to use shortcut menus in the Access run-time environment.
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

747 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now