Bỏ qua nội dung chính

 Làm thế nào để tạo danh sách thả xuống nhưng hiển thị các giá trị khác nhau trong Excel?

Trong trang tính Excel, chúng ta có thể nhanh chóng tạo danh sách thả xuống bằng tính năng Xác thực dữ liệu, nhưng, bạn đã bao giờ cố gắng hiển thị một giá trị khác khi bạn nhấp vào danh sách thả xuống chưa? Ví dụ: tôi có dữ liệu hai cột sau trong Cột A và Cột B, bây giờ, tôi cần tạo một danh sách thả xuống với các giá trị trong cột Tên, nhưng khi tôi chọn tên từ danh sách thả xuống đã tạo, giá trị trong cột Số được hiển thị như ảnh chụp màn hình sau. Bài viết này sẽ giới thiệu các chi tiết để giải quyết nhiệm vụ này.

doc thả xuống các giá trị khác nhau 1

Tạo danh sách thả xuống nhưng hiển thị giá trị khác trong ô danh sách thả xuống


Tạo danh sách thả xuống nhưng hiển thị giá trị khác trong ô danh sách thả xuống

Để hoàn thành tác vụ này, vui lòng thực hiện theo từng bước sau:

1. Tạo tên phạm vi cho các giá trị ô bạn muốn sử dụng trong danh sách thả xuống, trong ví dụ này, tôi sẽ nhập tên thả xuống trong Tên Box, và sau đó nhấn đăng ký hạng mục thi chính, xem ảnh chụp màn hình:

doc thả xuống các giá trị khác nhau 2

2. Sau đó, chọn các ô mà bạn muốn chèn danh sách thả xuống và nhấp vào Ngày > Xác nhận dữ liệu > Xác nhận dữ liệu, xem ảnh chụp màn hình:

doc thả xuống các giá trị khác nhau 3

3. Trong Xác nhận dữ liệu hộp thoại, bên dưới Cài đặt tab, chọn Danh sách từ Cho phép thả xuống, sau đó nhấp vào doc thả xuống các giá trị khác nhau 5 để chọn danh sách Tên mà bạn muốn sử dụng làm giá trị thả xuống trong nguồn hộp văn bản. Xem ảnh chụp màn hình:

doc thả xuống các giá trị khác nhau 4

4. Sau khi chèn danh sách thả xuống, vui lòng nhấp chuột phải vào tab trang tính hiện hoạt và chọn Mã Chế độ xem từ menu ngữ cảnh và trong Microsoft Visual Basic cho các ứng dụng cửa sổ, sao chép và dán mã sau vào Mô-đun trống:

Mã VBA: Hiển thị giá trị khác từ danh sách thả xuống:

Private Sub Worksheet_Change(ByVal Target As Range)
'Updateby Extendoffice
    selectedNa = Target.Value
    If Target.Column = 5 Then
        selectedNum = Application.VLookup(selectedNa, ActiveSheet.Range("dropdown"), 2, False)
        If Not IsError(selectedNum) Then
            Target.Value = selectedNum
        End If
    End If
End Sub

doc thả xuống các giá trị khác nhau 6

Chú thích: Trong đoạn mã trên, số 5 ở trong Nếu Target.Column = 5 Thì script là số cột mà danh sách thả xuống của bạn đặt, "thả xuống”Trong này selectNum = Application.VLookup (selectNa, ActiveSheet.Range ("dropdown"), 2, False) mã là tên dải ô bạn đã tạo ở bước 1. Bạn có thể thay đổi chúng theo ý muốn.

5. Sau đó, lưu và đóng mã này, bây giờ, khi bạn chọn một mục từ danh sách thả xuống, một giá trị tương đối khác được hiển thị trong cùng một ô, hãy xem ảnh chụp màn hình:

doc thả xuống các giá trị khác nhau 7


Demo: Tạo danh sách thả xuống nhưng hiển thị các giá trị khác nhau trong Excel

Kutools cho Excel: với hơn 300 bổ trợ Excel tiện dụng, dùng thử miễn phí không giới hạn trong 30 ngày. Tải xuống và dùng thử miễn phí ngay!

 

Công cụ năng suất văn phòng tốt nhất

🤖 Trợ lý AI của Kutools: Cách mạng hóa việc phân tích dữ liệu dựa trên: Thực thi thông minh   |  Tạo mã  |  Tạo công thức tùy chỉnh  |  Phân tích dữ liệu và tạo biểu đồ  |  Gọi các hàm Kutools...
Các tính năng phổ biến: Tìm, đánh dấu hoặc xác định các bản sao   |  Xóa hàng trống   |  Kết hợp các cột hoặc ô mà không làm mất dữ liệu   |   Vòng không có công thức hữu ích. Cảm ơn !
Siêu tra cứu: Nhiều tiêu chí VLookup    VLookup Nhiều Giá Trị  |   VLookup trên nhiều trang tính   |   Tra cứu mờ ....
Danh sách thả xuống nâng cao: Tạo nhanh danh sách thả xuống   |  Danh sách thả xuống phụ thuộc   |  Danh sách thả xuống nhiều lựa chọn ....
Trình quản lý cột: Thêm một số cột cụ thể  |  Di chuyển cột  |  Chuyển đổi trạng thái hiển thị của các cột ẩn  |  So sánh dãy và cột hữu ích. Cảm ơn !
Các tính năng nổi bật: Tiêu điểm lưới   |  Chế độ xem thiết kế   |   Thanh công thức lớn    Trình quản lý sổ làm việc & trang tính   |  Thư viện tài nguyên (Văn bản tự động)   |  Bảng chọn ngày   |  Kết hợp các bảng tính   |  Mã hóa/Giải mã ô    Gửi email theo danh sách   |  Siêu lọc   |   Bộ lọc đặc biệt (lọc in đậm/nghiêng/gạch ngang...) ...
15 bộ công cụ hàng đầu12 bản văn CÔNG CỤ (thêm văn bản, Xóa ký tự,...)   |   50 + Biểu đồ Các loại (Biểu đồ Gantt,...)   |   40+ Thực tế Công thức (Tính tuổi dựa trên ngày sinh,...)   |   19 chèn CÔNG CỤ (Chèn mã QR, Chèn ảnh từ đường dẫn,...)   |   12 Chuyển đổi CÔNG CỤ (Số thành từ, Chuyển đổi tiền tệ,...)   |   7 Hợp nhất & Tách CÔNG CỤ (Các hàng kết hợp nâng cao, Chia ô,...)   |   ... và nhiều hơn nữa

Nâng cao kỹ năng Excel của bạn với Kutools for Excel và trải nghiệm hiệu quả hơn bao giờ hết. Kutools for Excel cung cấp hơn 300 tính năng nâng cao để tăng năng suất và tiết kiệm thời gian.  Bấm vào đây để có được tính năng bạn cần nhất...

Mô tả


Tab Office mang lại giao diện Tab cho Office và giúp công việc của bạn trở nên dễ dàng hơn nhiều

  • Cho phép chỉnh sửa và đọc theo thẻ trong Word, Excel, PowerPoint, Publisher, Access, Visio và Project.
  • Mở và tạo nhiều tài liệu trong các tab mới của cùng một cửa sổ, thay vì trong các cửa sổ mới.
  • Tăng 50% năng suất của bạn và giảm hàng trăm cú nhấp chuột cho bạn mỗi ngày!

 

Comments (44)
No ratings yet. Be the first to rate!
This comment was minimized by the moderator on the site
Hello everyone,

About two years ago, @skyyang posted the following formula, which works perfectly:
Private Sub Worksheet_Change(ByVal Target As Range)
'Updateby Extendoffice
Dim xRg As Range
selectedNa = Target.Value
If Target.Column = 5 Then
Set xRg = ActiveWorkbook.Names("DropDown").RefersToRange
selectedNum = Application.VLookup(selectedNa, xRg, 2, False)
If Not IsError(selectedNum) Then
Target.Value = selectedNum
End If
End If
End Sub


However, I have six sections each needing the same results from the DDL name range. How do I get this formula to apply to more than one column please?

Any help would be greatly appreciated 🙂
This comment was minimized by the moderator on the site
How can I use this formula if the data for the drop down is on a sheet named materials?

Private Sub Worksheet_Change(ByVal Target As Range)
'Updateby Extendoffice
selectedNa = Target.Value
If Target.Column = 4 Then
selectedNum = Application.VLookup(selectedNa, ActiveSheet.Range("Material_List"), 2, False)
If Not IsError(selectedNum) Then
Target.Value = selectedNum
End If
End If
End Sub
This comment was minimized by the moderator on the site
Can this be applied to certain cells only instead of the whole column? It’s coming back as #N/A for some areas that i don't need this formula for. Thanks
This comment was minimized by the moderator on the site
The code I have used is below:


Private Sub Worksheet_Change(ByVal Target As Range)
'Updateby Extendoffice
selectedNa = Target.Value
If Target.Column = 8 Then
selectedNum = Application.VLookup(selectedNa, ActiveSheet.Range("codes"), 2, False)
If Not IsError(selectedNum) Then
Target.Value = selectedNum
End If
End If
End Sub



This works exactly how I need it too, however, when I save, close and then re-open the excel document, this has disappeared from the 'View Code' window and I have to re-insert the code again?????

Please help!
This comment was minimized by the moderator on the site
I have even saved the document as a Excel Macro-Enabled Workbook
This comment was minimized by the moderator on the site
Can you do multiple drop down lists like this on the same worksheet tab? How will the vba code be adjusted to accommodate different lists for the sheet?
This comment was minimized by the moderator on the site
Is there a way to return multiple selections to the same field? I.E. I want to show the numbers for Tedi, Dave and Lucy on a single field seperated by a comma.Many thanks.
This comment was minimized by the moderator on the site
This works for me but is there a way to allow multiple selections in the same cell? I.e. I wanted to return the numbers for Tedi, Lucy and Dave in a single field seperated by a comma?
This comment was minimized by the moderator on the site
Can this be done on different sheets? I mean, on sheet1 the range and on sheet2 the dropdown. How do I have to code this? Thanks.
This comment was minimized by the moderator on the site
Hello, Muhammd,To apply the drop down list in different worksheet, the following code may help you:Private Sub Worksheet_Change(ByVal Target As Range)
'Updateby Extendoffice
Dim xRg As Range
selectedNa = Target.Value
If Target.Column = 5 Then
Set xRg = ActiveWorkbook.Names("DropDown").RefersToRange
selectedNum = Application.VLookup(selectedNa, xRg, 2, False)
If Not IsError(selectedNum) Then
Target.Value = selectedNum
End If
End If
End Sub


Please try, thank you!
This comment was minimized by the moderator on the site
trying to do multiple drop downs sheet 1 , returning different worksheet. Is this possible as when i select in separate dropdown the sam numbers it does not work For example
Private Sub Worksheet_Change(ByVal Target As Range)
'Updateby Extendoffice

selectedNa = Target.Value
If Target.Column = 2 Then
Set xRg = ActiveWorkbook.Names("Supervisors").RefersToRange
selectedNum = Application.VLookup(selectedNa, xRg, 2, False)
If Not IsError(selectedNum) Then
Target.Value = selectedNum
selectedNa = Target.Value
End If
End If
selectedNa = Target.Value
If Target.Column = 9 Then
Set xRg = ActiveWorkbook.Names("Earth").RefersToRange
selectedNum = Application.VLookup(selectedNa, xRg, 2, False)
If Not IsError(selectedNum) Then
Target.Value = selectedNum
selectedNa = Target.Value

End If
End If
End Sub
This comment was minimized by the moderator on the site
Good morning i hope someone can help me.I used the VBA code above and it worked perfectly giving me my drop down showing me Different Values In Drop Down List Cell.My problem is that I need a second drop down list showing different values in a second list cell, on the same sheet, can anyone help me in doing this Kind Regards Rene
This comment was minimized by the moderator on the site
Se pueden usar diferentes “dropdown” en la misma hoja, para diferentes columnas y con diferentes rangos?Me explico, tengo una hoja en la que los usuarios introducen diferentes datos. En dos columnas 5 y 12 necesito validar la entrada con respecto a dos rangos diferentes de datos. Lo he probado solo con una columna y funciona perfectamente, pero no encuentro la manera de modificar el código VBA para la segunda columna
There are no comments posted here yet
Load More
Please leave your comments in English
Posting as Guest
×
Rate this post:
0   Characters
Suggested Locations