Resizing Array or similar method

SakiSam

New Member
Joined
Jul 25, 2014
Messages
20
Maybe I'm trying to use array's wrong but I need some help with the second/last loop where I am trying to change the contents of an array.

Here's the code.
Code:
Sub FeedReset(byValX As Boolean)
Dim nCalc As String, colStatTyp As Integer, ArrayData() As String, Element As Variant
ThisSpot   [COLOR=#008000]'Another Sub[/COLOR]
    Application.AutoCorrect.AutoFillFormulasInLists = True
    For r0 = 1 To 2 Step 1
        Select Case r0
            Case 1
                nPage = xPage10
                nCalc = "=[STATUS]&MID([TAG],4,1)|=MID([TAG],4,1)|=IF(COUNTIF(References!$B$4:$D$5,[StatusType])=1,""B"",""N"")|=IF(([YEAR]*1)>YEAR(NOW()),""Future"",IF(LEFT([YEAR],3)=LEFT(YEAR(NOW()),3),""Present"",IF((LEFT([YEAR],3)*1)=(LEFT(YEAR(NOW()),3)*1)-1,""Past"",IF((LEFT([YEAR],3)*1)<(LEFT(YEAR(NOW()),3)*1)-1,""Outdated""))))"
            Case 2
                nPage = xPage20
                nCalc = "=[cvmsstatus]&MID([tag],4,1)|=IF(COUNTIF(References!$B$4:$D$5,[StatusType])=1,""B"",""N"")|=MID([tag],4,1)|=IF(TRIM([noofdays])="""",0,IF([noofdays]>90,""90 + DAYS"",IF(AND([noofdays]>=61, [noofdays]<=90),""61-90 DAYS"",IF(AND([noofdays]>=30,[noofdays]<=60),""30-60 DAYS"",))))|=IF(ISNUMBER([Label]),0,1)"
        End Select
resetfilter nPage     [COLOR=#008000] 'Another sub that clears the autofilter of the named worksheet, if it is on.
        'Created to clear the "current" source [/COLOR][COLOR=#008000]pages, this will be repopulated with the latest data.[/COLOR]
         Sheets(nPage).Select
        If byValX Then Sheets(nPage).Range(nPage).EntireRow.Delete shift:=xlUp
        
        colStatTyp = Application.WorksheetFunction.Match("StatusType", Sheets(nPage).Range("1:1"), 0)
        ArrayData = Split(nCalc, "|")  [COLOR=#ff0000]'<-------Subsequent loops issue point[/COLOR]
        For Each Element In ArrayData
            Sheets(nPage).Cells(2, colStatTyp).Formula = Element
            colStatTyp = colStatTyp + 1
        Next Element
      [COLOR=#ff0000][B]  Erase ArrayData   '<------------------Issue Point, added when subsequent loops caused an error.[/B][/COLOR]
    Next r0
Return2ThisSpot[COLOR=#008000] 'Another Sub[/COLOR]
End Sub

So as you can see I have two tables that have different sets of formula's(nCalc) on the right side. Each table is a different data dump from a data warehouse (xpage 20 aka Aged inventory and 30-NotUsed). My issue occurs right before the Next command. The first nCalc splits into four elements and the second into five. I've tried adding "Erase" but I am getting an error that the array is currently in use.

I appreciate your time and assistance with this question.
Thank you,
 

Excel Facts

Test for Multiple Conditions in IF?
Use AND(test, test, test, test) or OR(test, test, test, ...) as the logical_test argument of IF.
Ok, I found my solution. Since the "Element" object had a value assigned to it, the system would not allow me to erase the array. Therefore I had to add
Code:
Set element = Nothing
right before the
Code:
[B]Erase ArrayData [/B]
line.

I hope this helps someone else.
 
Upvote 0

Forum statistics

Threads
1,223,231
Messages
6,170,884
Members
452,364
Latest member
springate

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top