简体   繁体   中英

Microsoft Excel VBA - drop down list auto populates multiple fields

I have an Excel workbook where on one sheet I have two columns of data.

For example:

ColumnA ColumnB
1000    DescriptionFor1000
1001    DescriptionFor1001
1002    DescriptionFor1002
1003    DescriptionFor1003
...

On another sheet, I have one column set with Data Validation so that each cell value must equal a value from ColumnA above (ex. 1000 or 1001 or 1002 etc).

When the user selects a value from the drop down list of ColumnA values, I would like the column next to it be autopopulated with ColumnB value from above.

For example, if the user selected 1001, the cell right next to it would automatically fill with "DescriptionFor1001"

I do not have code here because there is none to display (all controlled through Excel so far). Is there a way to do this? I do not mind writing VBA code if need be.

A VLOOKUP formula should do the trick. Let's assume the dropdown in in cell A1, and the data for the dropdown is in Sheet2!A1:B10 , the formula would be:

=VLOOKUP(A1,Sheet2!A1:B10,2,FALSE)

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