473,320 Members | 2,158 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

creating a multidimensional array help

Can anyone help me to change this array to a multidimensional array with 1 more components i want to add another "column" to the array with a similiar specification of "cell.Offset(0, -2).Value". So, actually want to add one more "column" as well, but it will contain another amount of similiar values of undetermined length as well. My Code is below, which also contains a section that puts the array into another sheet. Thank you all.

Expand|Select|Wrap|Line Numbers
  1. Public Sub DIFFREC()
  2. Dim cell As Variant
  3. Dim rw As Integer
  4. Dim x As Integer
  5. 'Dim rwCt As Integer
  6. 'rwCt = Range("myRange").Count
  7. Dim arrTicker() As String
  8. rw = 1 ' array counter
  9. For Each cell In Range("myRange")
  10.      If Abs(cell.Value) > 0 Then
  11.          ReDim Preserve arrTicker(rw)
  12.          arrTicker(rw - 1) = cell.Offset(0, -3).Value
  13.          rw = rw + 1
  14.      End If
  15. Next cell
  16. Windows("SENTRY.DIFF.05.07.xls").Activate
  17. For rw = 1 To UBound(arrTicker)
  18.      x = x + 1
  19.      Cells(x + 2, 1).Value = arrTicker(rw - 1)
  20. Next
  21. End Sub
  22.  
May 24 '07 #1
2 1625
danp129
323 Expert 256MB
Expand|Select|Wrap|Line Numbers
  1. Public Sub DIFFREC()
  2.     Dim cell As Variant
  3.     Dim rw As Integer
  4.     Dim x As Integer
  5.     'Dim rwCt As Integer
  6.     'rwCt = Range("myRange").Count
  7.     Dim arrTicker() As String   'Declare arrTicker as string array
  8.     rw = 0 ' array counter
  9.     For Each cell In Range("myRange")
  10.         If Abs(cell.Value) > 0 Then
  11.             ReDim Preserve arrTicker(0 To 1, rw) '(re)Dimension arrTicker(columns, rows)
  12.             arrTicker(0, rw) = cell.Offset(0, -3).Value
  13.             arrTicker(1, rw) = cell.Offset(0, -2).Value
  14.             rw = rw + 1
  15.         End If
  16.     Next cell
  17.     Windows("SENTRY.DIFF.05.07.xls").Activate
  18.     x = 0
  19.     For rw = 0 To UBound(arrTicker, 2)  ', 2' refers to 2nd dimension
  20.         x = x + 1
  21.         Cells(x + 1, 1).Value = arrTicker(0, rw)
  22.         Cells(x + 1, 2).Value = arrTicker(1, rw)
  23.     Next
  24. End Sub
Keep in mind when redimensioning a multi-dimension array you can only redimension the right most dimension.
This will work
Expand|Select|Wrap|Line Numbers
  1. ReDim Preserve arrTicker(0 To 1, mynewval)
This will not work
Expand|Select|Wrap|Line Numbers
  1. ReDim Preserve arrTicker(mynewval, 0 to 1)
You were also using a 0 based array but started from 1 and also were creating an array that was larger then what you currently needed. I changed it all to 0 based.
May 24 '07 #2
SammyB
807 Expert 512MB
Not too sure I understood your specs, but I would not bother with an array at all. The code below copies all of the positive cells in myRange which can be anywhere & have anynumber of columns. Positive cells are copied to the output workbook begining at A3. The output columns remain the same, but the output row is "collapsed" when the value is negative. If this is not what you want, let me know.
Expand|Select|Wrap|Line Numbers
  1. Sub DIFFREC()
  2.     Dim rIn As Range
  3.     Set rIn = Range("myRange")
  4.     Dim wsOut As Worksheet
  5.     Set wsOut = Windows("SENTRY.DIFF.05.07.xls").ActiveSheet
  6.     Dim rOut As Range
  7.     Set rOut = wsOut.Cells(3, 1)
  8.     Dim iCol As Integer, iRow As Integer
  9.     Dim i As Integer    ' Output row offset
  10.     For iCol = 1 To rIn.Columns.Count
  11.         i = 0
  12.         For iRow = 1 To rIn.Rows.Count
  13.             If rIn.Cells(iRow, iCol).Value > 0 Then
  14.                 rOut.Offset(i, iCol - 1) = rIn.Cells(iRow, iCol)
  15.                 i = i + 1
  16.             End If
  17.         Next iRow
  18.     Next iCol
  19. End Sub
  20.  
May 24 '07 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

5
by: TLOlczyk | last post by:
I have a brain cramp and I need some help. I have a chunk of code below which demonstrates a problem I have with multidimensional arrays. I want to keep it simple but something specific is...
5
by: TheKeith | last post by:
I can't figure out why this doesn't work: --------------------------------------------- greeting = new Array(); greeting = "hey"; greeting = "bye"; trace(greeting + greeting);
1
by: @ nospam.com | last post by:
Hi, If Im using Jagged arrays, the following is possible: int arr = new int for(int i=0; i<10; i++) { arr = new int; }
4
by: andy.mcvicker | last post by:
Hi Gang I have a large VB program that at one point does a lookup to a small table (26 rows by 3 columns). With this table I have to do some counting and retrieval of data. I'm finding that...
10
by: | last post by:
I'm fairly new to ASP and must admit its proving a lot more unnecessarily complicated than the other languages I know. I feel this is because there aren't many good official resources out there to...
11
by: Bigshot | last post by:
Im trying to scan a file using fscanf and want to put the results in a multidimensional array (since C has no strings I need it to store names). Basically I want to be able to have a...
2
by: nitinm | last post by:
hi I want to make a program whose requirement are as following: 1) it has to create an NxN matrix after reading input (i.e. N) from a file in the main() itself. 2) it has to send the array as...
5
by: LittleCake | last post by:
Hi All, I have a multidimensional array where each sub-array contains just two entries, which indicates a relationship between those two entries. for example the first sub-array: =Array ( =30...
9
by: Slain | last post by:
I need to convert a an array to a multidimensional one. Since I need to wrok with existing code, I need to modify a declaration which looks like this In the .h file int *x; in a initialize...
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.