Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

For Each loops and arrays/collections

Status
Not open for further replies.

Lenvdb

Programmer
Jun 21, 2002
81
GB
Hey all you VB gurus
I am just curious about using FOR EACH loops with arrays.

I know you can use it with a collections and sinle dimensional arrays. However I need to create a 2-dimensional array where I have to loop through the 2nd column and look for certain values in the rows.
Create the array:
Dim vArray(1 To 3, 1 To 2) As Variant
Dim i As Integer
Dim key As Variant

'Populate the Array
For i = 1 To 3
vArray(i, 1) = i
vArray(i, 2) = "Element No " & CStr(i)
Next

'Now display the values
For Each key In vArray
If key = "Element No 2" Then
MsgBox key
End If
Next

Can I let this loop search only one of the fields rather than all the values?

Rgds
Len

This goes through ALL the values in both fields(columns)
I simply need to go through the 2nd columns
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top