简体   繁体   中英

Excel-VBA combo box value on form load

I have a VBA form which is used to enter data on a sheet. I am currently coding the form so as it will load any data already existing in the sheet back into the form.

For simple text strings it works perfectly.

eg

ReqSetup.ReqText = Application.Worksheets("Req Sheet").Range("F11").Value

However, I have some combo boxes, that on the form, when they are selected will enter a number in the corresponding cell.

Fail 1. - Run Time Error 380 - Invalid property value.

    ReqSetup.MinPerKgCB = Application.Worksheets("Req Sheet").Range("C27").Value

Fail 2.

    Dim MinPerKg As Range
    Set MinPerKg = Application.Worksheets("Req Sheet").Range("C27")

    ReqSetup.MinPerKgCB = MinPerKg

I'm obviously doing something really simple wrong but I can't work out what it is!!

Kind Regards!

I have some combo boxes, that on the form, when they are selected will enter a number in the corresponding cell

Then you'd need to do the opposite of your code attempt, ie:

 Worksheets("Req Sheet").Range("C27").Value = ReqSetup.MinPerKgCB.Value

That you'd better wrap inside a check that any combobox value is actually selected :

With ReqSetup.MinPerKgCB
    If .ListIndex <> -1 Then Worksheets("Req Sheet").Range("C27").Value = .Value
End With

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM