PC Review


Reply
Thread Tools Rate Thread

Delete sheet on a condition: debug error

 
 
ucanalways@gmail.com
Guest
Posts: n/a
 
      13th Nov 2007
I have the following code.

The following sub is written for deleting a worksheet that has its
name as 0. Code works but I dont get the desired result.

Sub test1()

Dim ws as worksheet

For each ws InThisWorkbook.Worksheets

If ws.name = 0 then
Application.DisplayAlerts = False
ws.delete
End If

Next

End Sub

The following sub is written for deleting worksheets if its index
number is greater than 3. Again, Code works but dont get the desired
result.

Sub test2()
Dim ws as worksheet

For each ws InThisWorkbook.Worksheets
Application.DisplayAlerts = False
If ws.index > 3 then
ws.delete
End If

Next

End Sub

Any idea why this happens? Thanks

 
Reply With Quote
 
 
 
 
Colby Africa
Guest
Posts: n/a
 
      13th Nov 2007
Hey there.

What is the desired result?

C

 
Reply With Quote
 
ucanalways@gmail.com
Guest
Posts: n/a
 
      13th Nov 2007
On Nov 13, 12:54 pm, Colby Africa <colby.afr...@gmail.com> wrote:
> Hey there.
>
> What is the desired result?
>
> C


For test1, the desired result would be to delete the sheet that has
the name as 0
For test2, the desired result would be to delete the sheets that has
the index greater thanm 3.

test2 runs quite okay but test1 does not do what I intend to do

 
Reply With Quote
 
Colby Africa
Guest
Posts: n/a
 
      13th Nov 2007
I get it now. Okay, the worksheet Name property is a string, so try
something like this:



Dim ws As Worksheet


For Each ws In ActiveWorkbook.Worksheets


If ws.Name = "0" Then
Application.DisplayAlerts = False
ws.Delete
End If


Next


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
Entering Debug after delete sheet DocBrown Microsoft Excel Programming 12 5th Sep 2009 12:05 AM
Copy from one Sheet and paste on another sheet based on condition Prem Microsoft Excel Misc 2 24th Dec 2007 05:05 AM
PLEASE HELP! Copy sheet with password protected cells debug error bsnapool Microsoft Excel Programming 4 10th Jul 2006 11:59 AM
random Microsoft Visual C++ Debug Library Debug Error =?Utf-8?B?ZGNobWFu?= Microsoft Access VBA Modules 1 26th Apr 2006 03:25 PM
Visual C++ Debug Library. Debug Error! Abnormal program termination John Microsoft Outlook Discussion 1 25th Sep 2004 09:00 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 07:15 PM.