Relating variables in one array to variables in a second array

spidaman

Board Regular
Joined
Jul 26, 2015
Messages
116
Office Version
  1. 365
Platform
  1. Windows
I have two arrays - MyTArray and CtrArray - both of which have 5 variables. The variables refer to 2 corresponding sets of 5 textboxes on the same userform.

How do I make the 5 variables in the first array correspond with the variables in the second array? So I need to relate MyTArray(1) to CtrArray(1), MyTArray(2) to CtrArray(2) and so on.

I am trying to perform a look-up for each value in MyTArray (in another array my4Array) and return a value from the second column in each corresponding textbox in CtrArray.

This is a snippet of the code where I hope you can see what I'm trying to achieve:

VBA Code:
For i = 1 To UBound(MyTArray)
    If MyTArray(i) <> "" Then
        For k = LBound(my4Array, 1) To UBound(my4Array, 1)
            If my4Array(k, 1) = Left(MyTArray(1), 4) Then
                For m = 1 To UBound(CtrArray)
                    CtrArray(m).Text = ActiveWorkbook.Sheets("Sheet1").Cells(k, 2).Value
                Next m
            End If
        Next
    End If
Next i

The above is not returning a value in CtrArray textboxes. I know the issue is with the For/Next statement in the middle of the CtrArray as when I run it for a single variable specifying CtrArray(1) for example it does return a correct value.

Can anyone explain how I can relate the MyTArray to CtrArray please so that the look-up values are returned to the corresponding textboxes?
 
But what are the actual values?
 
Upvote 0

Excel Facts

Highlight Duplicates
Home, Conditional Formatting, Highlight Cells, Duplicate records, OK to add pink formatting to any duplicates in selected range.
But what are the actual values?
Apologies, i was replying from memory but have checked the data now and M1:27 have 4-digit numbers in each cell. In the textboxes are longer numbers - so I am looking up the first 4 digits on the left of the textbox values against the 4-digit numbers in M1:27 then returning string values from the cells on the righthand side in N1:27

Does that help?
 
Upvote 0
At the moment you are looking at the first 2 characters not the first 4. Try
VBA Code:
            If my4Array(k, 1) = Left(MyTArray(i), 4) Then
but if the values in M1:M27 are numbers & not text this will still fail.
 
Upvote 0
At the moment you are looking at the first 2 characters not the first 4. Try
VBA Code:
            If my4Array(k, 1) = Left(MyTArray(i), 4) Then
but if the values in M1:M27 are numbers & not text this will still fail.
Hi Fluff yes like you said the values in M1:M27 needed to be formatted as text. It works now!

Thanks very much for your help as always, much appreciated.
 
Upvote 0

Forum statistics

Threads
1,214,520
Messages
6,120,008
Members
448,935
Latest member
ijat

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