Results 1 to 4 of 4

Thread: ReDim Error

  1. #1

    ReDim Error



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

    I have a code like this
    Code:
    Private Sub Sample()
    Dim exstrn() As String
    Dim i As Integer
    i = 1
    Do
    i = i + 1 ReDim Preserve exstrn(0 To UBound(exstrn) + i) As String
    And I got error message Subscript out of range with ReDim Preserve
    Can you help me about that?

  2. #2
    Code:
    Private Sub Sample()
    Dim exstrn As Variant
    Dim i As Long
    
    
        ReDim exstrn(1 To 1)
        i = 1
        Do
            ReDim Preserve exstrn(1 To i)
            'do your stuff
            i = i + 1
        Loop

  3. #3
    Conjurer snb's Avatar
    Join Date
    May 2013
    Posts
    374
    Articles
    0
    Excel Version
    2020
    Code:
    sub M_snb()
        Dim sn() As String
        ReDim sn(0)
    
        Do
           ReDim Preserve sn(UBound(sn) + 1)
        Loop
    End Sub

  4. #4
    It worked very well.
    Thank you very much !

Posting Permissions

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