Results 1 to 2 of 2

Thread: Explanation needed

  1. #1

    Explanation needed



    Register for a FREE account, and/
    or Log in to avoid these ads!

    Hi!

    Can anybody please explain to me, what does the following part of code do?

    Code:
    Dim shNames() As String
    Dim DynamicArray() As Variant
    Dim i As Long, j As Long, k As Long
    Dim x As Long, y As Long
    
    k = Worksheets.Count
    j = k
    
    ReDim DynamicArray(2, j)
    
    For x = 1 To k
    rem DynamicArray(z, x) = Worksheets(x).Name
    Next x
    
    For i = z To k
    ReDim Preserve shNames(i)
    shNames(i) = DynamicArray(z, i)
    Next i
    
    Worksheets(shNames).Select

    It is a part of a macro that loops through every PivotItem in the PageField (Filter) of the Pivot Table, returns data and copy the data on new sheet for each PivotItem.
    If I don't run the code above, there is no problem - the pivot table is filtered and I get a new sheet for each PivotItem in the PageField. But when I run the code, I get a "Run-time error 9: Subscription out of Range".
    The reason for this error is the line

    Code:
    shNames(i) = DynamicArray(z, i)
    So I'd just like to know, what is the purpose of this code and how can I fix it, because I do not have much experience using the codes in Excel.

  2. #2
    I'd like to remov this thread as I post it elsewhere.

    Thanx.

Posting Permissions

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