Solved

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

Posted on 2013-01-04
5
362 Views
Last Modified: 2013-01-11
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
Comment
Question by:lep1
  • 3
  • 2
5 Comments
 
LVL 33

Expert Comment

by:Norie
Comment Utility
Use Resize with the dimensions of the array to get a range that matches the size of the array.
0
 

Assisted Solution

by:lep1
lep1 earned 0 total points
Comment Utility
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
 
LVL 33

Accepted Solution

by:
Norie earned 40 total points
Comment Utility
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
 
LVL 33

Expert Comment

by:Norie
Comment Utility
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
 

Author Closing Comment

by:lep1
Comment Utility
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

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

More often than not, we developers are confronted with a need: a need to make some kind of magic happen via code. Whether it is for a client, for the boss, or for our own personal projects, the need must be satisfied. Most of the time, the Framework…
Ever notice how you can't use a new drive in Windows without having Windows assigning a Disk Signature?  Ever have a signature collision problem (especially with Virtual Machines?)  This article is intended to help you understand what's going on and…
In this video, we discuss why the need for additional vertical screen space has become more important in recent years, namely, due to the transition in the marketplace of 4x3 computer screens to 16x9 and 16x10 screens (so-called widescreen format). …
With the advent of Windows 10, Microsoft is pushing a Get Windows 10 icon into the notification area (system tray) of qualifying computers. There are many reasons for wanting to remove this icon. This two-part Experts Exchange video Micro Tutorial s…

771 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now