How to get value of an Array in VBA

ggkrs4

New Member
Joined
Sep 10, 2008
Messages
18
I have a dynamic array. I want to get the value of each element in the array. I tried array.value and did not work. Can someone help me with it?

Sub TargetArrayValue()
Dim Target() As Integer
ReDim Preserve Target(10)
i = 1

tgtCurrency_ID = "ABC"

'Assigns value to the Target array
For rwIndex = 1 to 100
For colIndex = 2 to 2
With Worksheets("CrossCurrency").Cells(rwIndex,colIndex)
If .Value = tgtCurrency_ID Then
Target(i) = rwIndex 'Gets the rows that has the value 'ABC'
i = i+1
Next colIndex
Next rwIndex

'Want to get the values of the Target array
???????????????????

End Sub


Thanks in advance for the help.
 

Excel Facts

Enter current date or time
Ctrl+: enters current time. Ctrl+; enters current date. Use Ctrl+: Ctrl+; Enter for current date & time.
Like this perhaps

Code:
For i = LBound(Target) To UBound(Target)
    MsgBox Target(i)
Next i
 
Upvote 0
Thanks VoG II.

I wanted to get the elements of the array to compare two arrays.

eg.
Target() = (4, 8)
Settle() = (2, 5, 6, 8, 12)

I want to get the values so I can compare Target() and Settle() and get an output of "8".
 
Upvote 0
Code:
Sub test()
Dim ary1, ary2, e, temp As String, x
ary1 = Array(4, 8)
ary2 = Array(2, 5, 6, 8, 12)
For Each e In ary1
    x = Application.Match(e, ary2, 0)
    If Not IsError(x) Then temp = temp & " " & e
Next
MsgBox IIf(Len(temp), Join(Split(temp), vbLf), "No match")
End Sub
 
Upvote 0

Forum statistics

Threads
1,215,059
Messages
6,122,918
Members
449,094
Latest member
teemeren

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top