Consulting

Results 1 to 3 of 3

Thread: Saving worksheet range without formula to array

  1. #1
    VBAX Contributor
    Joined
    Jul 2017
    Location
    Zurich
    Posts
    132
    Location

    Saving worksheet range without formula to array

    Hi Folks

    Trying to save an entire worksheet to an array (in order to trim the values), however, excluding cells that contain any formula.

    So, my try was like so:


    For i = numSektionProdukte + 3 To numZeilenProdukte  
                For j = 3 To numSpaltenProdukte
                    If Not .Cells(i, j).HasFormula Then
                       arrProdukte(i - (numSektionProdukte + 2), j - 2) = .Cells(i, j)       'The first i = 9 and the first j is 3, so the first arrProdukte(1,1) would be 1,1 (Option base 1)
                    End If
                Next j
            Next i
    However, as soon as it comes to saving any value into the array, i get an error 9, Index out the range...

    Any ideas

  2. #2
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    Dim you dimension arrProdukte before the loop? If so, to what size? It worked for me when I did so, but an alternative approach is load the array and clear the formula values

        arrProdukte = .Range(.Cells(numSektionProdukte + 3, 3), .Cells(numZeilenProdukte, numSpaltenProdukte))
        For i = numSektionProdukte + 3 To numZeilenProdukte
     
            For j = 3 To numSpaltenProdukte
     
                If .Cells(i, j).HasFormula Then
     
                    arrProdukte(i - (numSektionProdukte + 2), j - 2) = Empty
                End If
            Next j
        Next i
        End With
    ____________________________________________
    Nihil simul inventum est et perfectum

    Abusus non tollit usum

    Last night I dreamed of a small consolation enjoyed only by the blind: Nobody knows the trouble I've not seen!
    James Thurber

  3. #3
    VBAX Contributor
    Joined
    Jul 2017
    Location
    Zurich
    Posts
    132
    Location
    Thank you that works

Posting Permissions

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