PC Review


Reply
Thread Tools Rate Thread

deleting worksheets msg box

 
 
Paulo
Guest
Posts: n/a
 
      5th Jun 2008
hi,
I am very new @ coding. just started yesterday...
I have 2 problems right now...
I have several tabs, and I whant a macro to erase em all, but , Sheet(1).
(1) my macro is kinda doing it, but i dont know how to make it to loop.
(2) as the macro runs the " Worksheets(DB).Delete " line, excel pops up a
msg box confirming the lost of data on the sheet deleted, how do i work
around that?

I thank in advance...
my curent code is
Private Sub CommandButton2_Click()
Dim x As Long
Dim DB As Long
Dim Wsht As Long
Wsht = Worksheets.Count
Debug.Print Wsht
For DB = 2 To Wsht
Debug.Print DB
Exit For
Next
Worksheets(DB).Delete
End Sub
 
Reply With Quote
 
 
 
 
JLGWhiz
Guest
Posts: n/a
 
      5th Jun 2008
Sub DeleShts()
Dim sh As Worksheet
For Each sh In ThisWorkbook.Sheets
If Sheet.Name <> "Sheet1" Then
sh.Delet
End If
Next
End Sub

"Paulo" wrote:

> hi,
> I am very new @ coding. just started yesterday...
> I have 2 problems right now...
> I have several tabs, and I whant a macro to erase em all, but , Sheet(1).
> (1) my macro is kinda doing it, but i dont know how to make it to loop.
> (2) as the macro runs the " Worksheets(DB).Delete " line, excel pops up a
> msg box confirming the lost of data on the sheet deleted, how do i work
> around that?
>
> I thank in advance...
> my curent code is
> Private Sub CommandButton2_Click()
> Dim x As Long
> Dim DB As Long
> Dim Wsht As Long
> Wsht = Worksheets.Count
> Debug.Print Wsht
> For DB = 2 To Wsht
> Debug.Print DB
> Exit For
> Next
> Worksheets(DB).Delete
> End Sub

 
Reply With Quote
 
Rick Rothstein \(MVP - VB\)
Guest
Posts: n/a
 
      5th Jun 2008
> I am very new @ coding. just started yesterday...

Out of curiosity, was it really easier to hit Shift+2 (assuming an American
keyboard) instead of simply typing "at"?<g>

> I have 2 problems right now...
> I have several tabs, and I whant a macro to erase em all, but , Sheet(1).
> (1) my macro is kinda doing it, but i dont know how to make it to loop.
> (2) as the macro runs the " Worksheets(DB).Delete " line, excel pops up a
> msg box confirming the lost of data on the sheet deleted, how do i work
> around that?


This code should do what you ask...

Sub RemoveSheets()
Dim X As Long
Worksheets(1).Select
On Error GoTo CleanUp
Application.DisplayAlerts = False
For X = Worksheets.Count To 2 Step -1
Worksheets(X).Delete
Next
CleanUp:
Application.DisplayAlerts = True
End Sub

Rick

 
Reply With Quote
 
Susan
Guest
Posts: n/a
 
      5th Jun 2008
JLG forgot about the warning you wanted ignored......
==========================
Option Explicit

Sub DeleShts()
Dim sh As Worksheet

Application.DisplayAlerts = False

For Each sh In ThisWorkbook.Sheets
If sh.Name <> "Sheet1" Then
sh.Delete
End If
Next

Application.DisplayAlerts = True

End Sub
=====================

susan


On Jun 5, 1:38*pm, JLGWhiz <JLGW...@discussions.microsoft.com> wrote:
> Sub DeleShts()
> * *Dim sh As Worksheet
> * *For Each sh In ThisWorkbook.Sheets
> * * *If Sheet.Name <> "Sheet1" Then
> * * * * sh.Delet
> * * *End If
> * *Next
> End Sub
>
>
>
> "Paulo" wrote:
> > hi,
> > I am very new @ coding. just started yesterday...
> > I have 2 problems right now...
> > I have several tabs, and I whant a macro to erase em all, but , Sheet(1)..
> > (1) my macro is kinda doing it, but i dont know how to make it to loop.
> > (2) as the macro runs the " Worksheets(DB).Delete " line, excel pops up a
> > msg box confirming the lost of data on the sheet deleted, how do i work
> > around that?

>
> > I thank in advance...
> > my curent code is
> > Private Sub CommandButton2_Click()
> > Dim x As Long
> > Dim DB As Long
> > Dim Wsht As Long
> > Wsht = Worksheets.Count
> > Debug.Print Wsht
> > For DB = 2 To Wsht
> > Debug.Print DB
> > Exit For
> > Next
> > Worksheets(DB).Delete
> > End Sub- Hide quoted text -

>
> - Show quoted text -


 
Reply With Quote
 
Paulo
Guest
Posts: n/a
 
      5th Jun 2008
Rick, worked great
tanks again, life saver...

"Rick Rothstein (MVP - VB)" wrote:

> > I am very new @ coding. just started yesterday...

>
> Out of curiosity, was it really easier to hit Shift+2 (assuming an American
> keyboard) instead of simply typing "at"?<g>
>
> > I have 2 problems right now...
> > I have several tabs, and I whant a macro to erase em all, but , Sheet(1).
> > (1) my macro is kinda doing it, but i dont know how to make it to loop.
> > (2) as the macro runs the " Worksheets(DB).Delete " line, excel pops up a
> > msg box confirming the lost of data on the sheet deleted, how do i work
> > around that?

>
> This code should do what you ask...
>
> Sub RemoveSheets()
> Dim X As Long
> Worksheets(1).Select
> On Error GoTo CleanUp
> Application.DisplayAlerts = False
> For X = Worksheets.Count To 2 Step -1
> Worksheets(X).Delete
> Next
> CleanUp:
> Application.DisplayAlerts = True
> End Sub
>
> Rick
>
>

 
Reply With Quote
 
Paulo
Guest
Posts: n/a
 
      5th Jun 2008
thanks for your help susan

"Susan" wrote:

> JLG forgot about the warning you wanted ignored......
> ==========================
> Option Explicit
>
> Sub DeleShts()
> Dim sh As Worksheet
>
> Application.DisplayAlerts = False
>
> For Each sh In ThisWorkbook.Sheets
> If sh.Name <> "Sheet1" Then
> sh.Delete
> End If
> Next
>
> Application.DisplayAlerts = True
>
> End Sub
> =====================
>
> susan
>
>
> On Jun 5, 1:38 pm, JLGWhiz <JLGW...@discussions.microsoft.com> wrote:
> > Sub DeleShts()
> > Dim sh As Worksheet
> > For Each sh In ThisWorkbook.Sheets
> > If Sheet.Name <> "Sheet1" Then
> > sh.Delet
> > End If
> > Next
> > End Sub
> >
> >
> >
> > "Paulo" wrote:
> > > hi,
> > > I am very new @ coding. just started yesterday...
> > > I have 2 problems right now...
> > > I have several tabs, and I whant a macro to erase em all, but , Sheet(1)..
> > > (1) my macro is kinda doing it, but i dont know how to make it to loop.
> > > (2) as the macro runs the " Worksheets(DB).Delete " line, excel pops up a
> > > msg box confirming the lost of data on the sheet deleted, how do i work
> > > around that?

> >
> > > I thank in advance...
> > > my curent code is
> > > Private Sub CommandButton2_Click()
> > > Dim x As Long
> > > Dim DB As Long
> > > Dim Wsht As Long
> > > Wsht = Worksheets.Count
> > > Debug.Print Wsht
> > > For DB = 2 To Wsht
> > > Debug.Print DB
> > > Exit For
> > > Next
> > > Worksheets(DB).Delete
> > > End Sub- Hide quoted text -

> >
> > - Show quoted text -

>
>

 
Reply With Quote
 
Paulo
Guest
Posts: n/a
 
      5th Jun 2008
JLGWIHIZ thanks for helping out ...

"JLGWhiz" wrote:

> Sub DeleShts()
> Dim sh As Worksheet
> For Each sh In ThisWorkbook.Sheets
> If Sheet.Name <> "Sheet1" Then
> sh.Delet
> End If
> Next
> End Sub
>
> "Paulo" wrote:
>
> > hi,
> > I am very new @ coding. just started yesterday...
> > I have 2 problems right now...
> > I have several tabs, and I whant a macro to erase em all, but , Sheet(1).
> > (1) my macro is kinda doing it, but i dont know how to make it to loop.
> > (2) as the macro runs the " Worksheets(DB).Delete " line, excel pops up a
> > msg box confirming the lost of data on the sheet deleted, how do i work
> > around that?
> >
> > I thank in advance...
> > my curent code is
> > Private Sub CommandButton2_Click()
> > Dim x As Long
> > Dim DB As Long
> > Dim Wsht As Long
> > Wsht = Worksheets.Count
> > Debug.Print Wsht
> > For DB = 2 To Wsht
> > Debug.Print DB
> > Exit For
> > Next
> > Worksheets(DB).Delete
> > End Sub

 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Deleting Worksheets El Bee Microsoft Excel Programming 3 6th Feb 2008 07:14 PM
Deleting Worksheets =?Utf-8?B?SmVmZg==?= Microsoft Excel Programming 1 18th Jul 2007 04:55 AM
Re: Deleting Worksheets Chip Pearson Microsoft Excel Programming 0 7th Dec 2006 06:45 PM
Re: Deleting Worksheets paul.robinson@it-tallaght.ie Microsoft Excel Programming 0 7th Dec 2006 06:36 PM
Deleting worksheets Microsoft Excel Misc 8 20th Sep 2004 07:49 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 11:08 PM.