PDA

View Full Version : Combo Box selection = 2 values set



xMesa
09-30-2016, 12:59 AM
Hello. I want to have 2 values getting set when i select a single line from a combo box.

I got my example from excel-easy.com/vba/examples/multicolumn-combo-box.html=

My code is here: pastebin.com/FwuaqcDf

So basically when i select the first line from the ComboBox


With Pclient
Pclient.ColumnCount = 2
Dim Client(1 To 15, 1 To 2) As String

Client(1, 1) = "CMN"
Client(2, 1) = "RSS"
Client(3, 1) = "ORD"
Client(4, 1) = "CEB"
Client(5, 1) = "GP-BE"
Client(6, 1) = "GP-ME"
Client(7, 1) = "MSL"
Client(8, 1) = "SSO"
Client(9, 1) = "SSO-QTE"
Client(10, 1) = "FZH"
Client(11, 1) = "BPO"
Client(12, 1) = "RAB"
Client(13, 1) = "E&D"
Client(14, 1) = "DEI"
Client(15, 1) = "CTD"

Client(1, 2) = "LSR000"
Client(2, 2) = "LSR000"
Client(3, 3) = "LSR002"
Client(4, 4) = "LSR051"
Client(5, 5) = "LSR001"
Client(6, 6) = "LSR001"
Client(7, 7) = "LSR007"
Client(8, 8) = "LSR005"
Client(9, 9) = "LSR005"
Client(10, 10) = "LSR014"
Client(11, 11) = "LSR027"
Client(12, 12) = "LSR003"
Client(13, 13) = "LSR042"
Client(14, 14) = "LSR041"
Client(15, 15) = "LSR040"

Pclient.List = Client
End With


i want the values to complete in these columns based on the selection



Cells(ActiveCell.Row, 2).Value = Pclient.Value
Cells(ActiveCell.Row, 3).Value = Pclient.Column(1).Value



But i get a error saying "Run-time error '9' subscript out of range"

Any tips on what i'm doing wrong?

offthelip
09-30-2016, 01:20 AM
Dim Client(1 To 15, 1 To 2) As String

Client(3, 3) = "LSR002"
Client(4, 4) = "LSR051"
Client(5, 5) = "LSR001"
Client(6, 6) = "LSR001"
Client(7, 7) = "LSR007"
Client(8, 8) = "LSR005"
Client(9, 9) = "LSR005"
Client(10, 10) = "LSR014"
Client(11, 11) = "LSR027"
Client(12, 12) = "LSR003"
Client(13, 13) = "LSR042"
Client(14, 14) = "LSR041"
Client(15, 15) = "LSR040"

[/CODE]



You have defined an 2 dimensional array "client" size 15 times 2 and then tried to use as a 15 times 15 array

xMesa
09-30-2016, 01:46 AM
I feel stupid :)

now i get a error on

Cells(ActiveCell.Row, 3).Value = Pclient.Column(1).Value

offthelip
09-30-2016, 02:07 AM
try

Cells(ActiveCell.Row, 3).Value = Pclient.Column(1)

xMesa
09-30-2016, 02:18 AM
it worked :D thank you!