0

Excel seems to display the first element of an array over and over in a column with the following code

      Dim fileNum() As String = {"1", "2"}
    xlSourceRange = xlWorkSheet.Range("N2:N" & fileNum.Length + 1)
    xlSourceRange.Value2 = fileNum

The entire range just fills up with 1. How can I make it so each element in the array is displayed in the column without having to manually assign each cell in a loop. I'm using the Microsoft.Office.Interlop.Excel if that matters.

1 Answer 1

1

Ok, now i got to an IDE so I can answer more intelligently. The problem is the array - Unfortunately, Excel adds ranges based upon a 2-d array. For your specific example, this bit of code would give you what you are looking for:

    Dim fileNum() As object = {{"1"}, {"2"}}
    xlSourceRange = xlWorkSheet.Range("N2:N" & fileNum.Length + 1)
    xlSourceRange.Value = fileNum

Hope this does the trick!

Sign up to request clarification or add additional context in comments.

3 Comments

You should edit your original answer if you think this is the correct approach. Alternatively delete your previous answer.
It worked thank you so very much. I was wondering how would you convert a one dimensional array of objects to a 2-D array of objects?
Just create a new array - Dim x(,) as Object - Then you can populate it using a for loop.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.