combo box selection to change values

G

Guest

Hi,

I have a userform with a combo box (cb1), a textbox (tx1), a button (bt1),
and a checkbox (ck1).

If the value of the combo box corresponds to the value in a range (Col1), I
would like the values in three other ranges (Col2, Col3 and Col4) associated
respectively with the textbox, the button and the checkbox, to change to
their current (i.e. altered) values.

I have the following code:

Dim i as integer
Dim va Col1 as variant, Col2 as variant, Col3 as variant, Col4 as variant

vaCol1 = [Col1]
vaCol2 = [Col2]
vaCol3 = [Col3]
vaCol4 = [Col4]

Redim vaColumns (1to Ubound(Col1), 1 to 4)
For i to Ubound(vaCol1)
vaColumns(i, 1) = vaCol1
vaColumns(i, 2) = vaCol2
vaColumns(i, 3) = vaCol3
vaColumns(i, 4) = vaCol4

If vaColumns(i,1) = cb1.value then
vaColumns(i, 2) = tx1.value
vaColumns(i, 3) = bt1.value
vaColumns(i, 4) = ck1.value
End if
Next i

Unfortunately, in stead of replacing the items in Col2, Col3 and Col4
selected via cb1, this code adds a row and inserts the previous (i.e.
unchanged) values of tx1, bt1 and ck1.

Any idea what I've done wrong?

Regards,

JVLin
 
M

Mark

Hi,
Dim i as integer
Dim va Col1 as variant, Col2 as variant, Col3 as variant,
Col4 as variant


Shouldn't this be
Dim i as integer
Dim vaCol1 as variant, vaCol2 as variant, vaCol3 as
variant, vaCol4 as variant

or is it just a typo when you posted it here?


Also, try cb1.text or
cb1.list(cb1.listindex)

tx1.text (not value)

How can a button have a value???

A check box has 3 values checked, unchecked and
graychecked, what value are you sufggesting

Apart form all this,

dim strCb1Txt as string
dim strHere as string
strHere=col1.value
strCb1Txt cb1.text


if strhere=strCb1Txt then
msgbox "Match"
end if

Something like this....

--Mark

-----Original Message-----
Hi,

I have a userform with a combo box (cb1), a textbox (tx1), a button (bt1),
and a checkbox (ck1).

If the value of the combo box corresponds to the value in a range (Col1), I
would like the values in three other ranges (Col2, Col3 and Col4) associated
respectively with the textbox, the button and the checkbox, to change to
their current (i.e. altered) values.

I have the following code:

Dim i as integer
Dim va Col1 as variant, Col2 as variant, Col3 as variant, Col4 as variant

vaCol1 = [Col1]
vaCol2 = [Col2]
vaCol3 = [Col3]
vaCol4 = [Col4]

Redim vaColumns (1to Ubound(Col1), 1 to 4)
For i to Ubound(vaCol1)
vaColumns(i, 1) = vaCol1
vaColumns(i, 2) = vaCol2
vaColumns(i, 3) = vaCol3
vaColumns(i, 4) = vaCol4

If vaColumns(i,1) = cb1.value then
vaColumns(i, 2) = tx1.value
vaColumns(i, 3) = bt1.value
vaColumns(i, 4) = ck1.value
End if
Next i

Unfortunately, in stead of replacing the items in Col2, Col3 and Col4
selected via cb1, this code adds a row and inserts the previous (i.e.
unchanged) values of tx1, bt1 and ck1.

Any idea what I've done wrong?

Regards,

JVLin


.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top