Help!

VBA Code Required for deleting All Sheets except Sheet1

 
  

Post new topic   General Reply to Topic (not reply to a specific post)    Forums Home -> General Discussions RSS
Next:  Import from Outlook Express?  
Author Message
Ms-Exl-Learner
External


Since: Sep 15, 2009
Posts: 25



PostPosted: Tue Nov 03, 2009 12:46 am    Post subject: VBA Code Required for deleting All Sheets except Sheet1
Archived from groups: microsoft>public>excel>misc (more info?)

Please help to delete all the sheets in a workbook except the First sheet
(i.e.) Sheet1.

Thanks for reading.

--------------------
(Ms-Exl-Learner)
--------------------
Back to top
Jarek Kujawa
External


Since: Jan 09, 2009
Posts: 36



PostPosted: Tue Nov 03, 2009 1:10 am    Post subject: Re: VBA Code Required for deleting All Sheets except Sheet1 [Login to view extended thread Info.]
Archived from groups: per prev. post (more info?)

Sub delsheets()
Dim sh as Sheet

For Each sh in ActiveWorkbook.Sheets
If sh.Name<>"Sheet1" Then
sh.Delete
End If
Next sh

End Sub

On 3 Lis, 09:46, Ms-Exl-Learner <Ms.Exl.Lear... RemoveThis @gmail.com> wrote:
> Please help to delete all the sheets in a workbook except the First sheet
> (i.e.) Sheet1.
>
> Thanks for reading.
>
> --------------------
> (Ms-Exl-Learner)
> --------------------
Back to top
Gary''s Student
External


Since: Oct 01, 2005
Posts: 3350



PostPosted: Tue Nov 03, 2009 1:18 am    Post subject: RE: VBA Code Required for deleting All Sheets except Sheet1 [Login to view extended thread Info.]
Archived from groups: per prev. post (more info?)

Sub SheetRemover()
k = Sheets.Count
For i = k To 2 Step -1
Sheets(i).Delete
Next
End Sub

--
Gary''s Student - gsnu200908


"Ms-Exl-Learner" wrote:

> Please help to delete all the sheets in a workbook except the First sheet
> (i.e.) Sheet1.
>
> Thanks for reading.
>
> --------------------
> (Ms-Exl-Learner)
> --------------------
>
Back to top
Ms-Exl-Learner
External


Since: Sep 15, 2009
Posts: 25



PostPosted: Tue Nov 03, 2009 1:38 am    Post subject: RE: VBA Code Required for deleting All Sheets except Sheet1 [Login to view extended thread Info.]
Archived from groups: per prev. post (more info?)

Thank you it’s working fine but if I run the Macro then its asking me to
Confirm Do you want to delete this sheet like that for each and every
worksheet before deleting. I am having 200 sheets for 200 times I need to
click or Press enter for deleting the sheets.

Please help me…

--------------------
(Ms-Exl-Learner)
--------------------



"Gary''s Student" wrote:

> Sub SheetRemover()
> k = Sheets.Count
> For i = k To 2 Step -1
> Sheets(i).Delete
> Next
> End Sub
>
> --
> Gary''s Student - gsnu200908
>
>
> "Ms-Exl-Learner" wrote:
>
> > Please help to delete all the sheets in a workbook except the First sheet
> > (i.e.) Sheet1.
> >
> > Thanks for reading.
> >
> > --------------------
> > (Ms-Exl-Learner)
> > --------------------
> >
Back to top
Ms-Exl-Learner
External


Since: Sep 15, 2009
Posts: 25



PostPosted: Tue Nov 03, 2009 1:47 am    Post subject: RE: VBA Code Required for deleting All Sheets except Sheet1 [Login to view extended thread Info.]
Archived from groups: per prev. post (more info?)

Not for 200 times 199 times. Please set the macro without any message box
confirmation.

--------------------
(Ms-Exl-Learner)
--------------------



"Ms-Exl-Learner" wrote:

> Thank you it’s working fine but if I run the Macro then its asking me to
> Confirm Do you want to delete this sheet like that for each and every
> worksheet before deleting. I am having 200 sheets for 200 times I need to
> click or Press enter for deleting the sheets.
>
> Please help me…
>
> --------------------
> (Ms-Exl-Learner)
> --------------------
>
>
>
> "Gary''s Student" wrote:
>
> > Sub SheetRemover()
> > k = Sheets.Count
> > For i = k To 2 Step -1
> > Sheets(i).Delete
> > Next
> > End Sub
> >
> > --
> > Gary''s Student - gsnu200908
> >
> >
> > "Ms-Exl-Learner" wrote:
> >
> > > Please help to delete all the sheets in a workbook except the First sheet
> > > (i.e.) Sheet1.
> > >
> > > Thanks for reading.
> > >
> > > --------------------
> > > (Ms-Exl-Learner)
> > > --------------------
> > >
Back to top
Gary''s Student
External


Since: Oct 01, 2005
Posts: 3350



PostPosted: Tue Nov 03, 2009 1:55 am    Post subject: RE: VBA Code Required for deleting All Sheets except Sheet1 [Login to view extended thread Info.]
Archived from groups: per prev. post (more info?)

Sub SheetRemover()
k = Sheets.Count
Application.DisplayAlerts = False
For i = k To 2 Step -1
Sheets(i).Delete
Next
Application.DisplayAlerts = True
End Sub


--
Gary''s Student - gsnu200908


"Ms-Exl-Learner" wrote:

> Not for 200 times 199 times. Please set the macro without any message box
> confirmation.
>
> --------------------
> (Ms-Exl-Learner)
> --------------------
>
>
>
> "Ms-Exl-Learner" wrote:
>
> > Thank you it’s working fine but if I run the Macro then its asking me to
> > Confirm Do you want to delete this sheet like that for each and every
> > worksheet before deleting. I am having 200 sheets for 200 times I need to
> > click or Press enter for deleting the sheets.
> >
> > Please help me…
> >
> > --------------------
> > (Ms-Exl-Learner)
> > --------------------
> >
> >
> >
> > "Gary''s Student" wrote:
> >
> > > Sub SheetRemover()
> > > k = Sheets.Count
> > > For i = k To 2 Step -1
> > > Sheets(i).Delete
> > > Next
> > > End Sub
> > >
> > > --
> > > Gary''s Student - gsnu200908
> > >
> > >
> > > "Ms-Exl-Learner" wrote:
> > >
> > > > Please help to delete all the sheets in a workbook except the First sheet
> > > > (i.e.) Sheet1.
> > > >
> > > > Thanks for reading.
> > > >
> > > > --------------------
> > > > (Ms-Exl-Learner)
> > > > --------------------
> > > >
Back to top
Ms-Exl-Learner
External


Since: Sep 15, 2009
Posts: 25



PostPosted: Tue Nov 03, 2009 2:02 am    Post subject: RE: VBA Code Required for deleting All Sheets except Sheet1 [Login to view extended thread Info.]
Archived from groups: per prev. post (more info?)

Thank you very much it’s working fine now…

--------------------
(Ms-Exl-Learner)
--------------------



"Gary''s Student" wrote:

> Sub SheetRemover()
> k = Sheets.Count
> Application.DisplayAlerts = False
> For i = k To 2 Step -1
> Sheets(i).Delete
> Next
> Application.DisplayAlerts = True
> End Sub
>
>
> --
> Gary''s Student - gsnu200908
>
>
> "Ms-Exl-Learner" wrote:
>
> > Not for 200 times 199 times. Please set the macro without any message box
> > confirmation.
> >
> > --------------------
> > (Ms-Exl-Learner)
> > --------------------
> >
> >
> >
> > "Ms-Exl-Learner" wrote:
> >
> > > Thank you it’s working fine but if I run the Macro then its asking me to
> > > Confirm Do you want to delete this sheet like that for each and every
> > > worksheet before deleting. I am having 200 sheets for 200 times I need to
> > > click or Press enter for deleting the sheets.
> > >
> > > Please help me…
> > >
> > > --------------------
> > > (Ms-Exl-Learner)
> > > --------------------
> > >
> > >
> > >
> > > "Gary''s Student" wrote:
> > >
> > > > Sub SheetRemover()
> > > > k = Sheets.Count
> > > > For i = k To 2 Step -1
> > > > Sheets(i).Delete
> > > > Next
> > > > End Sub
> > > >
> > > > --
> > > > Gary''s Student - gsnu200908
> > > >
> > > >
> > > > "Ms-Exl-Learner" wrote:
> > > >
> > > > > Please help to delete all the sheets in a workbook except the First sheet
> > > > > (i.e.) Sheet1.
> > > > >
> > > > > Thanks for reading.
> > > > >
> > > > > --------------------
> > > > > (Ms-Exl-Learner)
> > > > > --------------------
> > > > >
Back to top
Jarek Kujawa
External


Since: Jan 09, 2009
Posts: 36



PostPosted: Tue Nov 03, 2009 2:19 am    Post subject: Re: VBA Code Required for deleting All Sheets except Sheet1 [Login to view extended thread Info.]
Archived from groups: per prev. post (more info?)

forgot to include the

Application.DisplayAlerts = False
....
Application.DisplayAlerts = True

part


On 3 Lis, 10:10, Jarek Kujawa <bli....DeleteThis@gazeta.pl> wrote:
> Sub delsheets()
> Dim sh as Sheet
>
> For Each sh in ActiveWorkbook.Sheets
> If sh.Name<>"Sheet1" Then
> sh.Delete
> End If
> Next sh
>
> End Sub
>
> On 3 Lis, 09:46, Ms-Exl-Learner <Ms.Exl.Lear....DeleteThis@gmail.com> wrote:
>
>
>
> > Please help to delete all the sheets in a workbook except the First sheet
> > (i.e.) Sheet1.
>
> > Thanks for reading.
>
> > --------------------
> > (Ms-Exl-Learner)
> > --------------------- Ukryj cytowany tekst -
>
> - Poka¿ cytowany tekst -
Back to top
Display posts from previous:   
Post new topic   General Reply to Topic (not reply to a specific post)    Forums Home -> General Discussions All times are: Eastern Time (US & Canada) (change)
Page 1 of 1

 
You can post new topics in this forum
You can reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum