PC Review


Reply
Thread Tools Rate Thread

Delete the sheets in the current workbook which are not have coloredin the tab

 
 
vicky
Guest
Posts: n/a
 
      28th Dec 2009
i need a vba code to delete all the sheets whose sheet name are not
coloured .......
 
Reply With Quote
 
 
 
 
Peter T
Guest
Posts: n/a
 
      28th Dec 2009
Sub DelNonColouredTabs()
Dim i As Long
Dim s As String
Dim shot As Object

If Val(Application.Version) <= 9 Then
MsgBox "Coloured tabs N/A in this Excel version"
Exit Sub
End If

ReDim arrNames(1 To ActiveWorkbook.Sheets.Count)

For Each sht In ActiveWorkbook.Sheets
If VarType(sht.Tab.Color) = vbBoolean Then
i = i + 1
arrNames(i) = sht.Name
End If
Next

If i = ActiveWorkbook.Sheets.Count Then
MsgBox "Cannot delete all sheets in the Workbook"

ElseIf i > 0 Then
ReDim Preserve arrNames(1 To i)
s = arrNames(1)
For i = 2 To UBound(arrNames)
s = s & vbCr & arrNames(i)
Next

If MsgBox("Delete the following Sheets" & vbCr & s, _
vbOKCancel) = vbOK Then
On Error GoTo errH
Application.DisplayAlerts = False
For i = UBound(arrNames) To 1 Step -1
ActiveWorkbook.Sheets(arrNames(i)).Delete
Next
End If
ElseIf i = 0 Then
MsgBox "All sheet tabs are coloured"
End If

done:
Application.DisplayAlerts = True
Exit Sub
errH:
MsgBox Err.Description
Resume done

End Sub

Regards,
Peter T

"vicky" <(E-Mail Removed)> wrote in message
news:3ae1d6ac-a49c-489f-93b5-(E-Mail Removed)...
>i need a vba code to delete all the sheets whose sheet name are not
> coloured .......



 
Reply With Quote
 
excelent
Guest
Posts: n/a
 
      28th Dec 2009
Sub Terminate()
Application.DisplayAlerts = False
For Each ws In ActiveWorkbook.Sheets
If ws.Tab.ColorIndex = -4142 Then ws.Delete
Next
Application.DisplayAlerts = False
End Sub


"vicky" skrev:

> i need a vba code to delete all the sheets whose sheet name are not
> coloured .......
> .
>

 
Reply With Quote
 
Barb Reinhardt
Guest
Posts: n/a
 
      28th Dec 2009
Here's some basic code.

You will be asked if you want to delete the worksheets and you'll need to
acknowledge it. If you don't want to do that, put Application.DisplayAlerts
=FALSE and =TRUE around the delete line. Also, if you try to delete the
last sheet, it won't let you. You need to have at least one visible sheet in
the workbook. This should get you started.

Dim WS As Excel.Worksheet

For Each WS In ThisWorkbook.Worksheets
Debug.Print WS.Tab.ColorIndex
If WS.Tab.ColorIndex <> xlColorIndexNone Then
WS.Delete
End If
Next WS
--
HTH,

Barb Reinhardt



"vicky" wrote:

> i need a vba code to delete all the sheets whose sheet name are not
> coloured .......
> .
>

 
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
Macro to protect and unprotect all sheets of the current workbook Lostguy Microsoft Excel Programming 0 8th Jul 2008 01:43 AM
Fills page number of all sheets in current workbook dapanpan Microsoft Excel Programming 0 23rd Mar 2008 01:43 AM
Import multiple csv files into current workbook as separate sheets santosh Microsoft Excel Programming 3 24th Jan 2006 05:06 PM
Re: Delete all visible sheets in workbook... Tom Ogilvy Microsoft Excel Programming 0 23rd Aug 2005 05:53 PM
Delete Sheets in workbook when saved Logan Microsoft Excel Programming 4 20th Mar 2004 01:53 AM


Features
 

Advertising
 

Newsgroups
 


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