Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

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

Posted on 2013-01-04
5
366 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
ID: 38747028
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
ID: 38748734
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
ID: 38748833
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
ID: 38749439
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
ID: 38766423
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

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
SQL Help 27 57
Help with adding DLL file in Windows project 20 40
Unable to connect C# program to an SQL database - Exception occurs. 4 47
Easy filter aspnet 2 24
INTRODUCTION The purpose of this document is to demonstrate the Installation and configuration of the Data Protection Manager product. Note that this demonstration was prepared on the basis of Windows OS is 2008 R2 and DPM 2010. DATA PROTECTI…
The password reset disk is often mentioned as the best solution to deal with the lost Windows password problem. In Windows 2008, 7, Vista and XP, a password reset disk can be easily created. But besides Windows 7/Vista/XP, Windows Server 2008 and ot…
Windows 8 comes with a dramatically different user interface known as Metro. Notably missing from the new interface is a Start button and Start Menu. Many users do not like it, much preferring the interface of earlier versions — Windows 7, Windows X…
This is Part 3 in a 3-part series on Experts Exchange to discuss error handling in VBA code written for Excel. Part 1 of this series discussed basic error handling code using VBA. http://www.experts-exchange.com/videos/1478/Excel-Error-Handlin…

840 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