0

I have a transposed dynamic n x 2 array that is used to populate a combobox. The primary column alone is not descriptive enough to identify rows uniquely. I would like to use the row index to identify the untransposed column uniquely. Using both columns in the array could also be used for this but may prove problematic down the line. This question is closely related to this question.

I have used Me.cbo.ListIndex = 0 to retrieve the index value. Ideally, I'd like to assign the index of the row chosen in the combobox to a variable. The ultimate goal is to use the index in two ways:

  1. For finding the correct column to use in future calculations
  2. As a method for comparison against another combobox that uses the same array in order to ensure that the same row has not been chosen in both comboboxes

To visually illustrate the above, the original data looks like this:

a  b  c  b
1  2  3  4
A  B  C  B

The transposed array looks like this:

A  1
B  2
C  3
B  4

I would like to be able to make a distinction between selecting B2 and B4, ideally by preserving and comparing index 1 and 3 respectively (0-based).

ListIndex is from the documentation. There is no documentation that I could find about retrieving the index from the name except where the value in the selection is unique. Any Help is greatly appreciated

Bar-Tzur
  • 85
  • 1
  • 10
  • I tend to deal with these by joining the 2 columns of data into a single array with the index column padded to a fixed length so I can take left(???, X) from the selected value – Tin Bum May 08 '19 at 13:56
  • 2
    Suppose you have 2 comboboxes: cb1 and cb2. When nothing is selected, cb1.Listindex=-1 and cb2.Listindex=-1. When something is selected in both, then cb1.value and cb2.value contains the selected value from the comboboxes. If they are identical, then you can inspect the listindices to see if they are the same. – AcsErno May 08 '19 at 14:06
  • When a value is selected in one combobox, cant you just remove that from second combobox? thus ensuring that same value cannot be selected in both comboboxes – Zac May 08 '19 at 14:10
  • @Knee This is certainly viable but I expect the index is already there. I'm trying to figure out how to access and retain the value of the index, if that is possible. – Bar-Tzur May 08 '19 at 14:48
  • @Zac I could create another array from the current array once the first one is selected but I would still need the index to ensure I'm retrieving the correct column once the selection is made. In addition, removing an entry would change the cell index which means I would have to handle that when the selection is made in the second combobox. – Bar-Tzur May 08 '19 at 14:58
  • @AcsErno This is what I needed. I had tried assigning these to variables but it looks like the variables were assigned the -1 value rather than the actual index. by comparing the list indices against each other directly (i.e. `Me.cb1.ListIndex=Me.cb2.ListIndex` I was able to compare them appropriately. Thank you. – Bar-Tzur May 08 '19 at 15:09

0 Answers0