Macro to call specific values in dimmed araay

D

Dandeli0n

In my Word 2003 macro project a dimmed array is being build based on a matrix
in an Excel workbook.
The matrix is transfered into the array and the macro uses the values in
each row as variables in the further programming.

I would like to build a new macro that asks for a variable (popup), searches
for this variable in either the array or in the original workbook.
When the specific row is being found then I'd like to use the data as
variables in the rest of the macro

Can anyone help me??
 
J

Jean-Guy Marcil

Dandeli0n said:
In my Word 2003 macro project a dimmed array is being build based on a matrix
in an Excel workbook.
The matrix is transfered into the array and the macro uses the values in
each row as variables in the further programming.

I would like to build a new macro that asks for a variable (popup), searches
for this variable in either the array or in the original workbook.
When the specific row is being found then I'd like to use the data as
variables in the rest of the macro

Use the same code you already have to build the array, then search the
array. Here is some simple code to get you going (Of course, I have to build
an array just to show you how to search the array... You would repalce the
array building code I have with your own and modify the searching code
appropriately):


Sub FindArrayValue()

Dim strArray(2, 2, 2) As String
Dim i As Long
Dim j As Long
Dim k As Long
Dim strValue As String
Dim str0 As String
Dim str1 As String
Dim str2 As String

i = 0
j = 0
k = 0
For i = 0 To 2
For j = 0 To 2
For k = 0 To 2
strArray(i, j, k) = i & "_" & j & "_" & k
Next
Next
Next

strValue = InputBox("What Variable are you looking for (""x_y_z"" where
numbers must be between 0 and 2)?", "Get value")

i = 0
j = 0
k = 0
For i = 0 To 2
For j = 0 To 2
For k = 0 To 2
If strArray(i, j, k) = strValue Then
str0 = strArray(i, j, 0)
str1 = strArray(i, j, 1)
str2 = strArray(i, j, 2)
Exit For
End If
Next
Next
Next

MsgBox "The three variables associated with """ & strValue & """ are """ _
& str0 & """, """ & str1 & """ and """ & str2 & """.", _
vbInformation, "Results"

End Sub
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top