PDA

View Full Version : [SOLVED:] Write part of 2D Array to Sheet



ashleyuk1984
04-26-2020, 01:15 PM
Hi,

I've got a 2D array, and I basically want to dump part of it onto a sheet.

Screenshot of Locals window below.

https://images2.imgbox.com/97/3d/GIaeFCLp_o.jpg (http://imgbox.com/GIaeFCLp)

Let's say I want to dump the contents of MonthTotals(1,0) to MonthTotals(1,7) onto the sheet at A1:H1

What code can do that for me?

I've tried this:


Sheets("Sheet2").Range("A1").Resize(1, UBound(OverallData, 2) + 1).Value = OverallData

Which dumps Monthtotals(0,0) to MonthTotals(0,7), but if I change it to this:


Sheets("Sheet2").Range("A1").Resize(2, UBound(OverallData, 2) + 1).Value = OverallData

But then I get both Monthtotals(0,0) to MonthTotals(0,7) AND Monthtotals(1,0) to MonthTotals(1,7) underneath it...

All I want is Monthtotals(1,0) to MonthTotals(1,7)

Is this possible?

Thanks

paulked
04-26-2020, 01:54 PM
Try Index:



arr = Application.Index(MonthTotals, 1)
Sheet2.Range("A1:H1") = arr

ashleyuk1984
04-26-2020, 02:13 PM
Ahhh... interesting, Application.Index creates a 1D array of the data that I want.
Ok, I can work with that. :) Thanks

paulked
04-26-2020, 02:25 PM
:thumb