How to set values to a range vertically

K

-kve-

Hi,

I am writing a C# program that interacts with Excel.

When I have a range in Excel that contains a few "horizontal" cells (e.g.
"A1" to "D1"), I can fill the range with values from an array:

Microsoft.Office.Interop.Excel.Range rangeSeries = wsData.get_Range("A1",
"D1");
range.set_Value(missing, array);

But when I try to do the same thing, but with a range with vertical cells,
all the cells in the range get the value of the first array field.

Anyone knows how this can be done?
 
C

Charlie

I can't answer about C# but in VBA you need to dimension the array as Row X
Column to fit your range horizontally or vertically. Here's an example (I
always use 1-based arrays)

Option Base 1

Sub test()

Dim a1(1, 4)
Dim a2(4, 1)

a1(1, 1) = "A"
a1(1, 2) = "B"
a1(1, 3) = "C"
a1(1, 4) = "D"

a2(1, 1) = "E"
a2(2, 1) = "F"
a2(3, 1) = "G"
a2(4, 1) = "H"

Range("a1:d1") = a1
Range("a2:a5") = a2

End Sub
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top