• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 386
  • Last Modified:

VB.NET and Excel: Determine Cell Descriptor from Array Upper Bound

When you have a large array, how can you  quickly dump it to an Excel range?   Thus far, I am using something like:

Sheet.Range("A1", "BC2000").Value = xmatrix

Open in new window


But I need to dynamically determine the "BC2000" based on the upper bounds of the array.  How can this be done?
0
lep1
Asked:
lep1
  • 3
  • 2
2 Solutions
 
NorieVBA ExpertCommented:
Use Resize with the dimensions of the array to get a range that matches the size of the array.
0
 
lep1Author Commented:
My array is xarray(,) and the following was required in order to successfully fill the range using autosizing.   Thus, resize was not enough:

            Dim oXL As Excel.Application
            oXL = CreateObject("Excel.Application")
            oXL.Visible = True
            Dim oWB As Excel.Workbook
            Dim oSheet As Excel.Worksheet

            ' Get a new workbook.
            oWB = oXL.Workbooks.Add
            oSheet = oWB.ActiveSheet
            oSheet.Name = "mytest"

            Dim Rng As Excel.Range
            Rng = oSheet.Range("A1", Reflection.Missing.Value)
            Rng = Rng.Resize(xarray.GetLength(0), xarray.GetLength(1))
            Rng.Value = xarray

Open in new window

0
 
NorieVBA ExpertCommented:
I don't quite see why Resize wasn't enough.

You've used it with the dimensions of the array to get the correct range.
0
 
NorieVBA ExpertCommented:
Apologies, I assumed that you just needed a pointer because you only posted one line of code which I assumed was part of a larger block of code.
0
 
lep1Author Commented:
It would be more helpful for expert to provide all code necessary for solving an issue, and not to give pointers that cause users to continue to look for solutions.  I think users are not seeking coaching, rather explicit detailed solutions.
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

  • 3
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now