I have a 2-dimensional array [vtData(0, 0)] that is Dimensioned as a Variant; its Lbound for each dimension is 0 and its UBound for dimension1 is 4 and its UBound for dimension2 is 2; therefore, 15 elements. (This array is imported into my VBA Code from Bloomberg.)
I do NOT want to paste this array into a worksheet; however, in design mode only, I am using the following to do exactly that (and it works):
where UB1 is UBound for dimension1.Code:ActiveSheet.Range(Cells(8, 1), Cells(8 + UB1, 3)) = vtData(0, 0)
OK, I want to create 3 child arrays (one for each column) from the parent array. (My objective is to connect the individual elements for each column into one string, using a delimiter, and then paste that string into a specified cell in my worksheet.) This is my non-working code:
When stepping-thru my code:Code:Dim Col_One As Variant, x As Integer ReDim Col_One(UB1 + 1) For x = 0 To UB1 Col_One(x) = vtData(x, 0) Next x
when x = 0, there are no errors;
when x = 1, I get the dreaded 'subscript out of range' error.
Do I need to use WorksheetFunction.Transpose?
Thanks for a reply.
Last edited by Chuckles123; 08-22-2007 at 02:59 PM.
Hi there,
It's a bit difficult to diagnose with only the extract you've posted.
I can run the following code with no problems:
The only significant difference between your code & mine is that I've included a Dim statement for vtData - i.e. my code definitely "knows" what vtData is.Code:Sub TEST() Const UB1 As Integer = 4 Dim Col_One As Variant, x As Integer Dim vtData(4, 2) As Variant ReDim Col_One(UB1 + 1) For x = 0 To UB1 Col_One(x) = vtData(x, 0) Next x End Sub
Are you sure that this variant has been declared in your code before the posted extract executes? Obviously it needs to be declared either within the routine itself or at the module or the Public level.
Hope this is helpful.
Regards,
Greg M
Thanks Greg, for your prompt reply.
I should have been more specific in my help request. When I saidI should have used my Dim stmt, which isthat is Dimensioned as a VariantI tried using yourCode:Dim vtData As VariantTwo problems: 1) the number of columns is fixed at 3, but the number of rows is a variable; and 2) I get an error at the following stmtCode:Dim vtData(4, 2) As Variant(this is where the Bloomberg data is imported into my VBA Code) The Compile error: states "Can't assign to array".Code:vtData = BlpBulk.BlpSubscribe(sSec, sFld)
Obiously, there is more going on here than I am aware.
Any more ideas?
Since I am pulling in my array from Bloomberg, I have simulated the downloaded array; it has the same dimensions. My simulated array is:Using the following stmt:Code:Dim x As Integer, y As Integer 'POPULATE ARRAY For y = 0 To 2 '<<< THIS BECOMES UB2 For x = 0 To 4 '<<< THIS BECOMES UB1 vtData(x, y) = (x * y) + x + y Next x Next ymy code works using the simulated array instead of the one downloaded from Bloomberg; however, this does not solve my problem because I will not know the value of UB1 until the array is downloaded from Bloomberg.Code:Dim vtData(0 To 4, 0 To 2) As Variant
If I use my original Dim stmt for vtData, I get a "Type mismatch" error on the preceding vtData(x, y) = ... stmt for the simulated array.
Later
There are currently 1 users browsing this thread. (0 members and 1 guests)
Bookmarks