简体   繁体   中英

Vba combobox using non-active sheet

I have a combobox to a userform and the its not an activesheet in excel so not sure how to go about it.

The sheet name is "DoNotPrint - Rate Index" and the values within that sheet to appear in the combobox are the columns C2:AS2.

Private Sub ComboBox1_Change()

   Sheets("DoNotPrint - Rate Index").Range("C2:AS2") = ComboBox1.Value

End Sub

I tried this code and the combobox list isn't populating those column when the combobox list button is clicked.

组合框

The code you posted is for taking what's in the combobox and putting it on the sheet, when it's selected. But if I understand correctly your issue is you can't get the combobox populated. Because you are using a single row as your dataset and not a single column you will need to transpose your data.

Private Sub UserForm_Initialize()
    ComboBox1.List = WorksheetFunction.Transpose(Sheet1.Range("C2:AS2"))
End Sub

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