Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Microsoft Office > Excel VBA > Excel VBA
|
Excel VBA Discuss using VBA for Excel programming.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Excel VBA section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old May 10th, 2005, 07:09 AM
Friend of Wrox
 
Join Date: Jan 2005
Posts: 1,525
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via ICQ to crmpicco Send a message via AIM to crmpicco Send a message via MSN to crmpicco Send a message via Yahoo to crmpicco
Default Delete sheet IF sheetname doesnt contain string

I'm looking for code that will Delete a sheet IF sheetname doesnt contain the string 'rules'.

thanks.

Picco

www.crmpicco.co.uk
www.crmpicco.co.uk.tt
www.milklemonadechocolate.uk.tt
www.griswolds.uk.tt
www.piccosmini.co.uk.tt
www.morton.uk.tt
__________________
_______________________
Ayrshire Minis - a Mini E-Community
http://www.ayrshireminis.com
http://www.crmpicco.co.uk
 
Old May 10th, 2005, 08:52 AM
Friend of Wrox
 
Join Date: Jan 2005
Posts: 1,525
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via ICQ to crmpicco Send a message via AIM to crmpicco Send a message via MSN to crmpicco Send a message via Yahoo to crmpicco
Default

something like this, but this throws me an error:

Code:
Sub DeleteRulelessSheets()
    Dim sh As Variant

    Application.ScreenUpdating = False
    Application.DisplayAlerts = False
    On Error GoTo Exits:

    For Each sh In Sheets
        If Not Application.ActiveSheet.Name = "RULES" Then
            Application.ActiveSheet.Delete
        End If
    Next sh

Exits:
    Application.ScreenUpdating = True
    Application.DisplayAlerts = True
End Sub
www.crmpicco.co.uk
www.crmpicco.co.uk.tt
www.milklemonadechocolate.uk.tt
www.griswolds.uk.tt
www.piccosmini.co.uk.tt
www.morton.uk.tt
 
Old May 10th, 2005, 08:54 AM
Friend of Wrox
 
Join Date: Jan 2005
Posts: 1,525
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via ICQ to crmpicco Send a message via AIM to crmpicco Send a message via MSN to crmpicco Send a message via Yahoo to crmpicco
Default

i've put that code in here, do i have to have it after i activate the sheet?

Code:
   '... find out how many sheets there are in the contract
    iSheetCount = Worksheets.Count

    '... the main loop
    '... will loop through all the sheets
    For i = 1 To iSheetCount

Call DeleteRulelessSheets

        '... variable used to output what values were not found during the
        '... colour mapping process, this only accounts for when NONE of
        '... the variables inside the template file are found
        sNotFound = ""

        '... get the values of the current worksheet
        Worksheets(i).Activate
        iTotalRows = ActiveSheet.UsedRange.Rows.Count
        iTotalCols = ActiveSheet.UsedRange.Columns.Count

www.crmpicco.co.uk
www.crmpicco.co.uk.tt
www.milklemonadechocolate.uk.tt
www.griswolds.uk.tt
www.piccosmini.co.uk.tt
www.morton.uk.tt
 
Old May 11th, 2005, 05:34 AM
Friend of Wrox
 
Join Date: Jan 2005
Posts: 1,525
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via ICQ to crmpicco Send a message via AIM to crmpicco Send a message via MSN to crmpicco Send a message via Yahoo to crmpicco
Default

i have this code:
Code:
If controlSheet Like "RULES" Then
                        '... take the start of the content and the totalrows and total columns
                        content_range = Left(gaContentColour(j), 2)
                        content_range = content_range & ":" & getColumnLetter(iTotalCols) & iTotalRows

                        '... delete all empty cells in the content range then
                        '... shift them all left
                        Range(content_range).Select
                        Selection.SpecialCells(xlCellTypeBlanks).Select
                        Selection.Delete Shift:=xlToLeft
                    End If
controlSheet contains the name of the sheet , would this work

www.crmpicco.co.uk
www.crmpicco.co.uk.tt
www.milklemonadechocolate.uk.tt
www.griswolds.uk.tt
www.piccosmini.co.uk.tt
www.morton.uk.tt





Similar Threads
Thread Thread Starter Forum Replies Last Post
Excel Sheetname darkhalf Classic ASP Basics 4 July 17th, 2008 08:50 AM
Delete last a character in string dtho Excel VBA 27 December 7th, 2005 01:01 PM
Delete Topic doesnt work mehdi62b Forum and Wrox.com Feedback 4 October 4th, 2004 02:02 PM
Delete script doesnt execute kosla78 Classic ASP Basics 1 November 19th, 2003 07:44 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.