+ Reply to Thread
Results 1 to 4 of 4

Flexible Array Set if it was deleted before

Hybrid View

  1. #1
    Valued Forum Contributor
    Join Date
    03-28-2014
    Location
    Kuala Lumpur, Malaysia
    MS-Off Ver
    Excel 2016
    Posts
    702

    Flexible Array Set if it was deleted before

    Hi,

    I would like to write the array set of sheets name below BUT these sheets maybe deleted in the previous macro if it does not meet the criteria.

    e.g. lets say, sheets("ScorePerformance_BB") was deleted before, the code may not be able to run.

    how to resolve it
    For Each ws In Sheets(Array("ScorePerformance_BB", _
                                "ScorePerformance_RCB", _ 
                                "ScorePerformance_CC", _
                                "ScorePerformance_RFS", _
                                "ScorePerformance_FTG", _
                                "ScorePerformance_MINVT", _
                                "ScorePerformance_CR"))

  2. #2
    Forum Guru
    Join Date
    08-15-2004
    Location
    Tokyo, Japan
    MS-Off Ver
    2013 O.365
    Posts
    22,834

    Re: Flexible Array Set if it was deleted before

    One way
        Dim e, ws As Worksheet
        For Each e In Array("ScorePerformance_BB", _
                    "ScorePerformance_RCB", _
                    "ScorePerformance_CC", _
                    "ScorePerformance_RFS", _
                    "ScorePerformance_FTG", _
                    "ScorePerformance_MINVT", _
                    "ScorePerformance_CR")
            On Error Resume Next
            Set ws = Sheets(e)
            On Error GoTo 0
            If Not ws Is Nothing Then
                ' your code here
            End If
        Next

  3. #3
    Forum Guru :) Sixthsense :)'s Avatar
    Join Date
    01-01-2012
    Location
    India>Tamilnadu>Chennai
    MS-Off Ver
    2003 To 2010
    Posts
    12,788

    Re: Flexible Array Set if it was deleted before

    Sub ExampleCode()
    Dim arNew() As String, Ws As Worksheet, ar As Variant, x As Integer
    
    'This loop will check the availability of the sheets and load it in new array
    For Each ar In Array("ScorePerformance_BB", "ScorePerformance_RCB", _
                                "ScorePerformance_CC", "ScorePerformance_RFS", _
                                "ScorePerformance_FTG", "ScorePerformance_MINVT", _
                                "ScorePerformance_CR", "Sheet1")
        On Error Resume Next
            Set Ws = Sheets(ar)
        On Error GoTo 0
        
        If Not Ws Is Nothing Then
            ReDim Preserve arNew(0 To x)
            arNew(x) = ar
            x = x + 1
        End If
    Next ar
    
    'Only Available Sheets Are loaded in arNew Array
    For Each ar In arNew
        MsgBox ar
    Next ar
    
    End Sub


    If your problem is solved, then please mark the thread as SOLVED>>Above your first post>>Thread Tools>>
    Mark your thread as Solved


    If the suggestion helps you, then Click *below to Add Reputation

  4. #4
    Valued Forum Contributor
    Join Date
    03-28-2014
    Location
    Kuala Lumpur, Malaysia
    MS-Off Ver
    Excel 2016
    Posts
    702

    Re: Flexible Array Set if it was deleted before

    Hi Jindon & Sixthsense,


    Thanks a lot.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Array Storage Problem: Array Elements Deleted on 'End' Command
    By AidenS in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 07-15-2014, 10:38 AM
  2. Replies: 3
    Last Post: 07-10-2014, 12:06 PM
  3. conditional sum: can I make the array flexible
    By jash147 in forum Excel General
    Replies: 4
    Last Post: 11-02-2007, 02:25 AM
  4. If No is deleted in middle of sequence,Nos alter after deleted No
    By crusty53 in forum Excel - New Users/Basics
    Replies: 3
    Last Post: 06-20-2006, 04:55 AM
  5. [SOLVED] Flexible Charts
    By Phil in forum Excel Charting & Pivots
    Replies: 2
    Last Post: 01-27-2005, 11:06 AM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1