Question

I have a program that builds a 2D array from one of about 100 SQL procedures, then drops the content of the array into an Excel spreadsheet. Because the size of the array is variable, based on the procedure being run (and any parameters the procedure contains), the range of the excel spreadsheet has to be dynamic, meaning that I cannot hard code a range like "A1:R3"

Currently, I am using the following line of code to set the range:

objxlRange = objxlOutSheet.Range(Chr(strOutputArray.GetLowerBound(1) + 1 + 64) & (strOutputArray.GetLowerBound(0) + 1) & ":" & Chr(strOutputArray.GetUpperBound(1) + 1 + 64) & (strOutputArray.GetUpperBound(0) + 1))

Now, in 99 of the 100 procedures, this goes swimmingly without issue. However, there is the one procedure that we are having problems with. The data that we are using to run the procedure returns a dataset of 44 rows and 32 columns. I can hard code the range to A1:AF45, and the program runs, but trying to dynamically create that range, as I do for the other procudures, errors out returning an HRESULT:0x800A03EC

Is anyone able to help with this?

Était-ce utile?

La solution

You can use cells() to create your range.

range(cells(rowindex,columnindex).address & ":" & cells(rowindex,columnindex).address)

cells() uses integers to refer to the rows and columns so you should be able to use the values right out of you array.

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top