Bỏ qua nội dung chính

Làm thế nào để tự động hoàn thành khi nhập trong danh sách thả xuống Excel?

Đối với danh sách thả xuống xác thực dữ liệu có nhiều mục, bạn cần cuộn lên và xuống trong danh sách để tìm mục bạn cần hoặc nhập chính xác toàn bộ từ vào hộp danh sách. Có cách nào để làm cho danh sách thả xuống tự động hoàn thành khi nhập các ký tự tương ứng không? Điều này sẽ giúp mọi người làm việc hiệu quả hơn trong trang tính với danh sách thả xuống trong ô. Hướng dẫn này cung cấp hai phương pháp để giúp bạn đạt được nó.

Tạo danh sách thả xuống tự động hoàn thành bằng mã VBA
Dễ dàng tạo danh sách thả xuống tự động hoàn thành sau 2 giây

Các hướng dẫn khác cho danh sách thả xuống ...


Tạo danh sách thả xuống tự động hoàn thành bằng mã VBA

Vui lòng thực hiện như sau để danh sách thả xuống tự động hoàn thành sau khi nhập các chữ cái tương ứng vào ô.

Trước tiên, bạn cần chèn một hộp tổ hợp vào trang tính và thay đổi các thuộc tính của nó.
  1. Mở trang tính chứa các ô danh sách thả xuống mà bạn muốn chúng tự động hoàn thành.
  2. Trước khi chèn Combo box, bạn cần thêm tab Developer vào ribbon Excel. Nếu tab Nhà phát triển hiển thị trên dải băng của bạn, chuyển sang bước 3. Nếu không, hãy làm như sau để tab Trình phát triển hiển thị trong ruy-băng: Bấm Tập tin > Các lựa chọn để mở Các lựa chọn cửa sổ. Trong này Tùy chọn Excel cửa sổ, nhấp Tuy Biên ruy-băng trong ngăn bên trái, chọn Nhà phát triển và sau đó bấm vào OK cái nút. Xem ảnh chụp màn hình:
  3. Nhấp chuột Nhà phát triển > Chèn > Hộp tổ hợp (Điều khiển ActiveX).
  4. Vẽ một hộp tổ hợp trong bảng tính hiện tại. Nhấp chuột phải vào nó và sau đó chọn Bất động sản từ menu chuột phải.
  5. Trong tạp chí Bất động sản hộp thoại, vui lòng thay thế văn bản gốc trong (Tên) lĩnh vực với TempCombo.
  6. Tắt Chế độ thiết kế bằng cách nhấp chuột Nhà phát triển > Chế độ thiết kế.
Sau đó, áp dụng mã VBA bên dưới
  1. Nhấp chuột phải vào tab trang tính hiện tại và nhấp vào Mã Chế độ xem từ menu ngữ cảnh. Xem ảnh chụp màn hình:
  2. Trong phần mở đầu Microsoft Visual Basic cho các ứng dụng cửa sổ, vui lòng sao chép và dán mã VBA bên dưới vào cửa sổ Mã của trang tính.
    Mã VBA: Tự động điền khi nhập vào danh sách thả xuống
    Private Sub Worksheet_SelectionChange(ByVal Target As Range)
    'Update by Extendoffice: 2020/01/16
        Dim xCombox As OLEObject
        Dim xStr As String
        Dim xWs As Worksheet
        Dim xArr
        
        Set xWs = Application.ActiveSheet
        On Error Resume Next
        Set xCombox = xWs.OLEObjects("TempCombo")
        With xCombox
            .ListFillRange = ""
            .LinkedCell = ""
            .Visible = False
        End With
        If Target.Validation.Type = 3 Then
            Target.Validation.InCellDropdown = False
            Cancel = True
            xStr = Target.Validation.Formula1
            xStr = Right(xStr, Len(xStr) - 1)
            If xStr = "" Then Exit Sub
            With xCombox
                .Visible = True
                .Left = Target.Left
                .Top = Target.Top
                .Width = Target.Width + 5
                .Height = Target.Height + 5
                .ListFillRange = xStr
                If .ListFillRange = "" Then
                    xArr = Split(xStr, ",")
                    Me.TempCombo.List = xArr
                End If
                .LinkedCell = Target.Address
            End With
            xCombox.Activate
            Me.TempCombo.DropDown
        End If
    End Sub
    Private Sub TempCombo_KeyDown(ByVal KeyCode As MSForms.ReturnInteger, ByVal Shift As Integer)
        Select Case KeyCode
            Case 9
                Application.ActiveCell.Offset(0, 1).Activate
            Case 13
                Application.ActiveCell.Offset(1, 0).Activate
        End Select
    End Sub
  3. Ấn Bản Khác + Q các phím đồng thời để đóng Ứng dụng Microsoft Visual Basic cửa sổ.

Từ bây giờ, khi nhấp vào một ô danh sách thả xuống, danh sách thả xuống sẽ tự động nhắc. Bạn có thể bắt đầu nhập chữ cái để tự động hoàn thành mục tương ứng trong ô đã chọn. Xem ảnh chụp màn hình:

Lưu ý: Mã này không hoạt động đối với các ô đã hợp nhất.

Dễ dàng tạo danh sách thả xuống tự động hoàn thành sau 2 giây

Đối với hầu hết người dùng Excel, phương pháp VBA trên khó thành thạo. Nhưng với Danh sách thả xuống có thể tìm kiếm tính năng của Kutools cho Excel, bạn có thể dễ dàng bật tính năng tự động hoàn tất cho danh sách thả xuống xác thực dữ liệu trong một phạm vi cụ thể chỉ trong 2 giây. Hơn nữa, tính năng này có sẵn cho tất cả các phiên bản Excel.

Mẹo: Trước khi áp dụng công cụ này, vui lòng cài đặt Kutools cho Excel trước hết. Tải xuống miễn phí ngay bây giờ.

  1. Để bật tính năng tự động hoàn thành trong danh sách thả xuống của bạn, trước tiên hãy chọn phạm vi có danh sách thả xuống. Sau đó, điều hướng đến Kutools tab, chọn Danh sách thả xuống > Làm cho danh sách thả xuống có thể tìm kiếm được, tự động bật lên.
  2. Trong tạp chí Làm cho danh sách thả xuống có thể tìm kiếm được hộp thoại, bấm vào OK để lưu cài đặt.
Kết quả

Sau khi cấu hình hoàn tất, nhấp vào ô danh sách thả xuống trong phạm vi đã chỉ định sẽ hiển thị hộp danh sách. Khi nhập các ký tự, miễn là một mục khớp chính xác, toàn bộ từ đó sẽ ngay lập tức được đánh dấu trong hộp danh sách và có thể được điền vào ô danh sách thả xuống chỉ bằng cách nhấn phím Enter.

Chú thích: Để áp dụng tính năng này, vui lòng tải xuống và cài đặt Kutools cho Excel Đầu tiên. Hoặc bạn có thể bấm vào để biết thêm về tính năng này.

Các bài liên quan:

Làm thế nào để tạo danh sách thả xuống với nhiều hộp kiểm trong Excel?
Nhiều người dùng Excel có xu hướng tạo danh sách thả xuống với nhiều hộp kiểm để chọn nhiều mục từ danh sách mỗi lần. Trên thực tế, bạn không thể tạo danh sách có nhiều hộp kiểm với Xác thực dữ liệu. Trong hướng dẫn này, chúng tôi sẽ chỉ cho bạn hai phương pháp để tạo danh sách thả xuống với nhiều hộp kiểm trong Excel. Hướng dẫn này cung cấp phương pháp để giải quyết vấn đề.

Tạo danh sách thả xuống từ một sổ làm việc khác trong Excel
Khá dễ dàng để tạo danh sách sổ xuống xác thực dữ liệu giữa các trang tính trong sổ làm việc. Nhưng nếu dữ liệu danh sách bạn cần để xác thực dữ liệu nằm trong một sổ làm việc khác, bạn sẽ làm gì? Trong hướng dẫn này, bạn sẽ học cách tạo danh sách drop fown từ một sổ làm việc khác trong Excel một cách chi tiết.

Tạo danh sách thả xuống có thể tìm kiếm trong Excel
Đối với một danh sách thả xuống với nhiều giá trị, việc tìm một giá trị thích hợp không phải là một công việc dễ dàng. Trước đây, chúng tôi đã giới thiệu một phương pháp tự động hoàn thành danh sách thả xuống khi nhập ký tự đầu tiên vào hộp thả xuống. Bên cạnh chức năng tự động hoàn thành, bạn cũng có thể làm cho danh sách thả xuống có thể tìm kiếm được để nâng cao hiệu quả làm việc trong việc tìm kiếm các giá trị thích hợp trong danh sách thả xuống. Để làm cho danh sách thả xuống có thể tìm kiếm được, hãy thử phương pháp trong hướng dẫn này.

Tự động điền các ô khác khi chọn giá trị trong danh sách thả xuống của Excel
Giả sử bạn đã tạo một danh sách thả xuống dựa trên các giá trị trong phạm vi ô B8: B14. Khi bạn chọn bất kỳ giá trị nào trong danh sách thả xuống, bạn muốn các giá trị tương ứng trong phạm vi ô C8: C14 được tự động điền vào một ô đã chọn. Để giải quyết vấn đề, các phương pháp trong hướng dẫn này sẽ giúp bạn.

Các hướng dẫn khác cho danh sách thả xuống ...

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 (325)
No ratings yet. Be the first to rate!
This comment was minimized by the moderator on the site
Hi, many thanks for this material. It helped a lot.
This comment was minimized by the moderator on the site
Hello,

following on from my last comment:

I'm setting up 'standard' rows with the dropdown lists in them. These I'm wanting to copy below into an extensive spreadsheet.
Unfortunately the dropdown's don't copy down when I do that after using the VBA.
Is there a way to do whats described above?

Cheers,
Catherine
This comment was minimized by the moderator on the site
Hi Catherine,
The autocomplete drop-down lists generated by VBA code cannot be copied. You can only copy selected items that are displayed in the drop-down cell. Sorry for the inconvenience.
This comment was minimized by the moderator on the site
Hello,

Have implemented this successfully, so thank you for this page and code.
But now I have an associated problem...:

After doing all of the above points, the code works as described, but I cannot do any undo/redo actions in the entire spreadsheet.
Is there a way to turn this combo box on for when I want to work with the dropdowns and off for when I want to work in other cells? so that the undo/redo actions are possible again?
and note, yes I have turned the design mode off after doing the above steps, but it still doesn't help the problem.

Cheers,
Catherine
This comment was minimized by the moderator on the site
Hi Catherine Foley,
If you want to use the undo operation on cells other than the drop-down cells, the following VBA code can help you. Please give it a try.
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
'Update by Extendoffice: 2022/09/22
    Dim xCombox As OLEObject
    Dim xStr As String
    Dim xWs As Worksheet
    Dim xArr
    
    On Error Resume Next

    Set xWs = Application.ActiveSheet
    
    Set xCombox = xWs.OLEObjects("TempCombo")
    If Target.Validation.Type <> 3 Then
        If xCombox.Visible Then
            xCombox.Visible = False
        End If
        Exit Sub
    End If
    
    With xCombox
        .ListFillRange = ""
        .LinkedCell = ""
'        .Visible = False
    End With

    Target.Validation.InCellDropdown = False
    Cancel = True
    xStr = Target.Validation.Formula1
    xStr = Right(xStr, Len(xStr) - 1)
    If xStr = "" Then Exit Sub
    With xCombox
        .Visible = True
        .Left = Target.Left
        .Top = Target.Top
        .Width = Target.Width + 5
        .Height = Target.Height + 5
        .ListFillRange = xStr
        If .ListFillRange = "" Then
            xArr = Split(xStr, ",")
            Me.TempCombo.List = xArr
        End If
        .LinkedCell = Target.Address
    End With
    xCombox.Activate
    Me.TempCombo.DropDown

End Sub
Private Sub TempCombo_KeyDown(ByVal KeyCode As MSForms.ReturnInteger, ByVal Shift As Integer)
    Select Case KeyCode
        Case 9
            Application.ActiveCell.Offset(0, 1).Activate
        Case 13
            Application.ActiveCell.Offset(1, 0).Activate
    End Select
End Sub
This comment was minimized by the moderator on the site
I hope now it will be upload
This comment was minimized by the moderator on the site
This code works really well for a single drop down. However, if I have 5 dropdowns using the same list of values but they need to operate independently of each other how is that accomplished? Despite my best efforts, if I put more than one combo box on the page, any selection is one is mirrored in the other.
This comment was minimized by the moderator on the site
Hi Mbuchmeier,Only need one combo box on the page. The code works on all drop-down lists in current page. You just need to manually click on the drop-down list cell to activate the combo box.
This comment was minimized by the moderator on the site
Hi crystal,
I am working with the combo box (The VBA code from 2021/11/05). It is working great and very useful but there are 2 issues:1. Issue #1: Usually when you work on any cell in Excel, there is indication on the row number which indicate which row you work about. When the combo box is opened this indication is missing2.  Issue #2: When the combo box is opened in the last column of the dynamic table, then it isn't  working as usual: when I select value from the list, the cell remain empty until I move the cursor to another cell
Attached screenshot.
Thank in advance
This comment was minimized by the moderator on the site
Hi Yoni,Thanks for your feedback. For the issues you mentioned:1. Issue #1: Excel does not highlight the row number when selecting an object in the worksheet. Since we use a combo box to replace the data validation drop-down list to handle the autocomplete operation, we can't show the indication in this case;2. Issue #2: I have tried as you described, but the problem cannot be reproduced. The screenshot you attached does not display, you need to save the screenshot and uplode it via the "Upload files" button below.
This comment was minimized by the moderator on the site
Hi Crystal,Thanks a lot for your response. Attached the screenshot. hope it will work now
This comment was minimized by the moderator on the site
Hi Yoni,Sorry for the inconvenience. The screenshot you uploaded is still not shown on the page. You need to save the screenshot on your disk in advance and then uplode it via the "Upload files" button. See the attached screenshot.
This comment was minimized by the moderator on the site
will, thank you is not enugh :::: alot of thank you then ;;;;; that worked like magic :)
This comment was minimized by the moderator on the site
Yeah, basically completely useless.  Want the cell to auto-complete when typing in a cell using list data validation.Tried this, and now I have to start over from scratch because I can't Undo it.  Thanks.Also loaded with syntax errors.
This comment was minimized by the moderator on the site
It works as it should be except for two things, first, there is no validation after insertion. i.e. if I typed anything at the combo then clicked enter it will accept the typed value while it should not do this since the data validation is being used to prevent such behaviors and make sure that the entered data is from selected range. Second, at the data validation list, sometimes I use big range with empty cells and select ignore empty at validation list but the combo takes all the range and shows it, will be nice to remove the empty cells from the combo range.
Thanks & hope you can implement these things to make it perfect.
This comment was minimized by the moderator on the site
Hi, AhmedThe VBA below helps to solve the problem of blank cells. Since the Combo box accepts the value that are not in the list, we still can't find a way to solve this problem. Sorry for the inconvenience.
<div data-tag="code">Private Sub Worksheet_SelectionChange(ByVal Target As Range)
'Update by Extendoffice: 2021/11/05
Dim xCombox As OLEObject
Dim xStr As String
Dim xWs As Worksheet
Dim xArr, xArr1
Dim xRg As Range
Dim xSrc As Variant
Dim xI, xJ, xIndex, xCount As Integer

Set xWs = Application.ActiveSheet
On Error Resume Next
Set xCombox = xWs.OLEObjects("TempCombo")
With xCombox
.ListFillRange = ""
.LinkedCell = ""
.Visible = False
End With
If Target.Validation.Type = 3 Then
Target.Validation.InCellDropdown = False
Cancel = True
xStr = Target.Validation.Formula1
xStr = Right(xStr, Len(xStr) - 1)
If xStr = "" Then Exit Sub
Set xRg = Range(xStr)
If xRg Is Nothing Then
xArr1 = Split(xStr, ",")
Else
ReDim xArr1(0 To xRg.Count - 1)
For xI = 0 To xRg.Count - 1
xArr1(xI) = xRg.Item(xI + 1).Value
Next
End If
xI = 0
xCount = UBound(xArr1) + 1
For xJ = 0 To UBound(xArr1)
If Replace(xArr1(xJ), " ", "") = "" Then xCount = xCount - 1
Next
ReDim xArr(0 To xCount - 1)
xIndex = 0
For xJ = 0 To UBound(xArr1)
If Replace(xArr1(xJ), " ", "") <> "" Then
xArr(xIndex) = xArr1(xJ)
xIndex = xIndex + 1
End If
Next
xStr = ""
With xCombox
.Visible = True
.Left = Target.Left
.Top = Target.Top
.Width = Target.Width + 5
.Height = Target.Height + 5
.ListFillRange = xStr
If .ListFillRange = "" Then
'xArr = Split(xStr, ",")
Me.TempCombo.List = xArr
End If
.LinkedCell = Target.Address
End With
xCombox.Activate
Me.TempCombo.DropDown
End If
End Sub
Private Sub TempCombo_KeyDown(ByVal KeyCode As MSForms.ReturnInteger, ByVal Shift As Integer)
Select Case KeyCode
Case 9
Application.ActiveCell.Offset(0, 1).Activate
Case 13
Application.ActiveCell.Offset(1, 0).Activate
End Select
End Sub
This comment was minimized by the moderator on the site
Hi Crystal,
I am working with the combo box (The VBA code from 2021/11/05). It is working great and so useful! thanks a lot.
I found the source of my problem. There was a line of freeze panes which override the combo box.
The only problem now is that the Undo is not working. Any idea?
Thanks in advanced,
Yoni
This comment was minimized by the moderator on the site
Hi,
The code does not support Undo. Sorry for the inconvenience.
This comment was minimized by the moderator on the site
Thanks. Maybe do you know why Worksheet_Change event is not firing once I choose value from the combo box?
This comment was minimized by the moderator on the site
Hi, could you please doublecheck this code, when I use it instead of the dropdown list appearing, the source for the dropdown appears instead. This is the exact function I want, could you please fix it.
This comment was minimized by the moderator on the site
If you use a named range or something similar, like I have with a table column, it will display the named range name instead of the values in that named range. To get what you want, you need to change the xStr to display the worksheet range of that named range, since the .ListFillRange does not take in named ranges directly. This should accomplish it : dim RangeAddress as String: RangeAddress = Range(YourNamedRange).addressand then make the xStr something like this: xStr = "YourWorksheetNameWithTheNamedRangeInIt!" & RangeAddress (important: add the '!' for the sheet reference)
This will make your xStr look something like: NamedRangeSheet!$A$1:$A$5
xStr = Right(xStr, Len(xStr) - 1)

If .ListFillRange = "" Then
xArr = Split(xStr, ",")
Me.TempCombo.List = xArr
End If

with these adjustments your combobox should display the list values instead of the source
This comment was minimized by the moderator on the site
Hi Syu,Sorry I don't quite understand your description. Can you try to be more specific of it?After applying the VBA code mentioned in the above method, when the cell with the data validation drop-down list is checked, the drop-down list turn into a combo box, and then all the items in the list are listed. 
This comment was minimized by the moderator on the site
do you have an example file please?
This comment was minimized by the moderator on the site
Hello. The code is very cool. Please make sure that the formula "INDIRECT" is carried out and displayed. It is very necessary
This comment was minimized by the moderator on the site
The code is not working for a validation list which is created by vba code and the source is a named range
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