Indirect Reference to a Variable in VBA

Arul.rajesh

Active Member
Joined
Sep 20, 2011
Messages
285
I have a list of values which are names of arrays

Something like

Code:
 CDS=Array(CIPR,CIPW,PTPA,CSRP,CITR,CPER,CPCT,CPSC,CW9D,VMLE,VMAD,AUTH,AUTE,AUTB,AUTL,NMRC,NMRE,NMRF,NMFR,CDTF,DTFA,CDTE,CNOF,CFWA,CDED,CDES,DEDR,CCOB,PEOB,CCOD,BMAX,MAXS,CNCS,CNPI,CFAX,CAPP,DEFA,CPEE,CPFL,CFWU,CFWE,CCAP,AUTW,CITW,CIPE,CDUP,CPNL,BMBS,ADDI,POSR,CLIC,CLIA,COIN,HOSP,OONP,POST,PPMX,PPMD,PROV)


Each four digit string is an array.

The user selects an option from a ComboBox

I need to Set the value of a another variable to an element in the array referenced by the "CODE" the user selects.

The problem is the selected text is a string.

I can loop through all the codes and check if the user has selected which "CODE", if I have the name of the array as the first element in the array.
 
Hi Arul

What you want is not allowed by the vba syntax.

The closest I see would be to use something like an associative array. You could use a Collection or a Dictionary object to implement it.

Notice that in this case you'd create the association of the arrays with the strings at the beginning of the execution. You would then have a direct access to the arrays using the strings during the rest of the execution of the program.
 
Upvote 0

Excel Facts

How to calculate loan payments in Excel?
Use the PMT function: =PMT(5%/12,60,-25000) is for a $25,000 loan, 5% annual interest, 60 month loan.
Hi Arul

What you want is not allowed by the vba syntax.

The closest I see would be to use something like an associative array. You could use a Collection or a Dictionary object to implement it.

Notice that in this case you'd create the association of the arrays with the strings at the beginning of the execution. You would then have a direct access to the arrays using the strings during the rest of the execution of the program.
I did do something like that

In the arrays I set the first element as the name of the array, then looped through all the arrays to check for a match with the first element to locate the required array.

I have 59 arrays defined like this, so it is pretty fast for now.

Thank you everyone for your Help.
 
Upvote 0

Forum statistics

Threads
1,223,227
Messages
6,170,848
Members
452,361
Latest member
d3ad3y3

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