Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 820165
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T02:25:55+00:00 2026-05-15T02:25:55+00:00

I am looking at someone else’s vba excel code. they are doing ReDim Preserve

  • 0

I am looking at someone else’s vba excel code. they are doing ReDim Preserve dataMatrix(7, i) in both loops. What does this do?

Also, it seems like the second loop just overwrites the data in the first loop, is that correct?

Dim dataMatrix() As String

    Worksheets.Item("ETS").Select
    Do While Trim(Cells(r, 1)) <> ""
       Debug.Print "The line: ", Trim(Cells(r, 1)), r
        r = r + 1
        dataMatrix(1, i) = Trim(Cells(r, 1))    ''file name
        dataMatrix(2, i) = Trim(Cells(r, 2))    ''sample type
        dataMatrix(3, i) = Trim(Cells(r, 3))    ''sample name
        dataMatrix(4, i) = "ETS"    ''
        dataMatrix(5, i) = Trim(Cells(r, 5))    ''Response
        dataMatrix(6, i) = Trim(Cells(r, 6))    ''ISTD Response
        dataMatrix(7, i) = Trim(Cells(r, 10))   ''Calculated Conc
        i = i + 1
        ReDim Preserve dataMatrix(7, i)
    Loop

    r = 5
    Worksheets.Item("ETG").Select
    Do While Trim(Cells(r, 1)) <> ""
       Debug.Print "The line: ", Trim(Cells(r, 1)), r
        r = r + 1
        dataMatrix(1, i) = Trim(Cells(r, 1))    ''file name
        dataMatrix(2, i) = Trim(Cells(r, 2))    ''sample type
        dataMatrix(3, i) = Trim(Cells(r, 3))    ''sample name
        dataMatrix(4, i) = "ETG"
        dataMatrix(5, i) = Trim(Cells(r, 5))    ''Response
        dataMatrix(6, i) = Trim(Cells(r, 6))    ''ISTD Response
        dataMatrix(7, i) = Trim(Cells(r, 10))   ''Calculated Conc
        i = i + 1
        ReDim Preserve dataMatrix(7, i)
    Loop
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-15T02:25:55+00:00Added an answer on May 15, 2026 at 2:25 am

    ReDim preservers a data in an array when you modify its size. Also it shouldn’t overwrite the data becasuse i is incremented every iteration of the loop: the first loop won’t stop until it encounters an empty cell, changing array length every iteration by one, so that when the lenght is 8 it adds 1 to the i and the new length becomes 9. When the second iteration occurs it writes the new element to the bound of the array with index 9, modifies its length again so that it becomes 1 element longer and iterates until encounters an empty line.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I was looking at someone else's code and noticed they called 'release' on an
I was looking through someone's code one day and I was annoyed how they
I was looking at someone else's code and wondering why anyone would do it
I am looking over someone Else's code and noticed that some of the user
I'm looking through someone else's code and am not sure what this means. It
Just learning php and looking into someone else's code. I'm not sure what is
Im looking at some source code written by someone else and its intrigues me
I am looking over some code someone else did and I see this: if
I'm a beginner w/ Javascript. I'm looking at the following code that someone else
I am looking into someone else's code and do not have much experience with

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.