Consulting

Results 1 to 4 of 4

Thread: Write part of 2D Array to Sheet

  1. #1

    Write part of 2D Array to Sheet

    Hi,

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

    Screenshot of Locals window below.



    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
    Last edited by ashleyuk1984; 04-26-2020 at 01:32 PM. Reason: Changing title from "Print" to "Write" - Sounds better

  2. #2
    VBAX Master paulked's Avatar
    Joined
    Apr 2006
    Posts
    1,007
    Location
    Try Index:

        arr = Application.Index(MonthTotals, 1)
        Sheet2.Range("A1:H1") = arr
    Semper in excretia sumus; solum profundum variat.

  3. #3
    Ahhh... interesting, Application.Index creates a 1D array of the data that I want.
    Ok, I can work with that. Thanks

  4. #4
    VBAX Master paulked's Avatar
    Joined
    Apr 2006
    Posts
    1,007
    Location
    Semper in excretia sumus; solum profundum variat.

Posting Permissions

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