简体   繁体   中英

Excel VBA cell comboBox (data validation list) set selected index?

I am using Excel VBA to make an simple app, I have a CELL with Data Validation make it a "ComboBox" , can I use VBA code to set the selectedIndex for it? and how?

在此处输入图片说明

If I understood correctly and you need to "put some value into CELL when worksheet with CELL on it is opened" then try to insert following code into ThisWorkbook module:

Private Sub Workbook_SheetActivate(ByVal Sh As Object)
    If Sh.Name = "%%SheetWithCELL%%" Then
        Sh.Range("CELL").Value = "%%NeededValue%%"
    End If
End Sub

Where

  • %%SheetWithCELL%% - Name of sheet where CELL is located;

  • %%NeededValue%% - Value, which you need to insert into CELL.

PS Code assumes that "CELL" is the actual name of some cell (named range)

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