跳到主要內容

如何從下拉列表中選擇多個項目到Excel中的單元格中?

下拉列表在Excel的日常工作中經常使用。 默認情況下,在下拉列表中只能選擇一項。 但是有時,您可能需要從下拉列表中將多個項目選擇到一個單元格中,如下圖所示。 如何在Excel中處理它?

doc從下拉列表1中選擇多個項目 doc箭頭向右 doc從下拉列表2中選擇多個項目

從下拉列表中選擇多個項目到帶有VBA的單元格中

從下拉列表中輕鬆快速地選擇多個項目到一個單元格中


從下拉列表中選擇多個項目到帶有VBA的單元格中

這裡有一些VBA可以幫您解決此工作。

從單元格的下拉列表中選擇重複項

1.創建下拉列表後,右鍵單擊工作表選項卡以選擇 查看代碼 從上下文菜單。
doc從下拉列表3中選擇多個項目

2.然後在 Microsoft Visual Basic for Applications 窗口,將下面的代碼複製並粘貼到空白腳本中。

VBA:從單元格的下拉列表中選擇多個項目

Private Sub Worksheet_Change(ByVal Target As Range)
'UpdatebyExtendoffice20221111
    Dim xRgVal As Range
    Dim xStrNew As String
    On Error Resume Next
    Set xRgVal = Cells.SpecialCells(xlCellTypeAllValidation)
    If (Target.Count > 1) Or (xRgVal Is Nothing) Then Exit Sub
    If Intersect(Target, xRgVal) Is Nothing Then Exit Sub
    If Target.Value = "" Then Exit Sub
    Application.EnableEvents = False
    xStrNew = Target.Value
    Application.Undo
    If xStrNew = Target.Value Then
    Else
    xStrNew = xStrNew & " " & Target.Value
    Target.Value = xStrNew
    End If
    Application.EnableEvents = True
End Sub

3.保存代碼並關閉窗口以返回到下拉列表。 現在,您可以從下拉列表中選擇多個項目。

注意:

1.使用VBA,它可以按空格分隔項目,您可以更改 xStrNew = xStrNew& “” & 目標價值 他人根據需要更改定界符。 例如, xStrNew = xStrNew&“," & 目標價值 將用逗號分隔項目。

2.此VBA代碼適用於工作表中的所有下拉列表。

從下拉列表中選擇多個項目到一個單元格,無需重複

如果只想從下拉列表中選擇一個唯一項,則可以重複上述步驟並使用以下代碼。

VBA:從下拉列表到單元格中選擇多個項目,無需重複

Private Sub Worksheet_Change(ByVal Target As Range)
'UpdatebyExtendoffice20221111
    Dim I As Integer
    Dim xRgVal As Range
    Dim xStrNew As String
    Dim xStrOld As String
    Dim xFlag As Boolean
    Dim xArr
    On Error Resume Next
    Set xRgVal = Cells.SpecialCells(xlCellTypeAllValidation)
    If (Target.Count > 1) Or (xRgVal Is Nothing) Then Exit Sub
    If Intersect(Target, xRgVal) Is Nothing Then Exit Sub
    If Target.Value = "" Then Exit Sub
    Application.EnableEvents = False
    xFlag = True
    xStrNew = " " & Target.Value & " "
    Application.Undo
    xStrOld = Target.Value
    If InStr(1, xStrOld, xStrNew) = 0 Then
        xStrNew = xStrNew & xStrOld & " "
    Else
        xStrNew = xStrOld
    End If
    Target.Value = xStrNew
    Application.EnableEvents = True
End Sub

以上兩個 VBA 代碼都不支持刪除部分單元格內容,只支持清除單元格的所有項。


從下拉列表中輕鬆快速地選擇多個項目到一個單元格中

在 Excel 中,除了 VBA 代碼,沒有其他方法允許從單元格中的下拉列表中選擇多個項目。 但是,那 多選下拉列表 的特點 Excel的Kutools 只需點擊一下即可快速輕鬆地處理此工作。

尖端:在套用此工具之前,請先安裝 Kutools for Excel。 立即前往免費下載.
步驟1:選擇 Kutools > 下拉列表 > 多選下拉列表
第 2 步:在多選下拉列表對話框中,指定設置
  1. 設置範圍;
  2. 指定分隔單元格中項目的分隔符;
  3. 決定文字方向;
  4. 單擊“確定”。
    doc 從下拉列表 kte 1 中選擇多個項目
結果:

從下拉列表 kutools 中選擇多個項目

備註:要使用多重選取下拉清單功能,您應該先安裝Kutools for Excel,請 點擊下載並立即免費試用 30 天.

在Excel中輕鬆創建動態的2級或多級依賴下拉列表

在Excel中,創建2級或多級下拉列表很複雜。 在這裡 動態下拉列表 的效用 Excel的Kutools 可以幫你一個忙。 您唯一要做的就是按示例所示對數據進行排序,然後選擇數據范圍和輸出範圍,然後將其留給實用程序。  點擊免費試用30天!
doc高級合併行
 
Kutools for Excel:擁有300多個便捷的Excel加載項,可以在30天內免費試用。

最佳辦公生產力工具

熱門特色: 尋找、突出顯示或識別重複項   |  刪除空白行   |  合併列或儲存格而不遺失數據   |   沒有公式的回合 ...
超級查詢: 多條件VLookup    多值VLookup  |   跨多個工作表的 VLookup   |   模糊查詢 ....
高級下拉列表: 快速建立下拉列表   |  依賴下拉列表   |  多選下拉列表 ....
欄目經理: 新增特定數量的列  |  移動列  |  切換隱藏列的可見性狀態  |  比較範圍和列 ...
特色功能: 網格焦點   |  設計圖   |   大方程式酒吧    工作簿和工作表管理器   |  資源庫 (自動文字)   |  日期選擇器   |  合併工作表   |  加密/解密單元格    按清單發送電子郵件   |  超級濾鏡   |   特殊過濾器 (過濾粗體/斜體/刪除線...)...
前 15 個工具集12 文本 工具 (添加文本, 刪除字符,...)   |   50+ 圖表 類型 (甘特圖,...)   |   40+ 實用 公式 (根據生日計算年齡,...)   |   19 插入 工具 (插入二維碼, 從路徑插入圖片,...)   |   12 轉化 工具 (數字到單詞, 貨幣兌換,...)   |   7 合併與拆分 工具 (高級合併行, 分裂細胞,...)   |   ... 和更多

使用 Kutools for Excel 增強您的 Excel 技能,體驗前所未有的效率。 Kutools for Excel 提供了 300 多種進階功能來提高生產力並節省時間。  點擊此處獲取您最需要的功能...

kte選項卡201905


Office選項卡為Office帶來了選項卡式界面,使您的工作更加輕鬆

  • 在Word,Excel,PowerPoint中啟用選項卡式編輯和閱讀,發布者,Access,Visio和Project。
  • 在同一窗口的新選項卡中而不是在新窗口中打開並創建多個文檔。
  • 將您的工作效率提高 50%,每天為您減少數百次鼠標點擊!
Comments (26)
No ratings yet. Be the first to rate!
This comment was minimized by the moderator on the site
Como posso utilizar a função com a planilha bloqueada?
This comment was minimized by the moderator on the site
Hi, Macros, try below code, it supports to select multi items in drop down list in protected sheet.
Private Sub Worksheet_Change(ByVal Target As Range)
'UpdatebyExtendoffice20221111
    Dim xRgVal As Range
    Dim xStrNew As String
    On Error Resume Next  
    xType = 0
    xType = Target.Validation.Type
    If xType <> 3 Then Exit Sub
    If (Target.Count > 1) Then Exit Sub

    If Target.Value = "" Then Exit Sub
    Application.EnableEvents = False
    xStrNew = Target.Value
    Application.Undo
    If xStrNew = Target.Value Then
    Else
    xStrNew = xStrNew & " " & Target.Value
    Target.Value = xStrNew
    End If
    Application.EnableEvents = True
End Sub

And also Kutools for Excel 26.1 and later versions supports this job in protected sheet.
This comment was minimized by the moderator on the site
¿Cómo puedo hacer para que el orden en que se coloque el texto, sea tan cuál como yo quiera?

Ejemplo:
Mi texto para la lista es:
TRAMITAR ESTE ASUNTO
COORDINAR
ANALIZAR Y RECOMENDAR

sí selecciono:
TRAMITAR ESTE ASUNTO
ANALIZAR Y RECOMENDAR

me aparece
ANALIZAR Y RECOMENDAR, TRAMITAR ESTE ASUNTO

o sea, los de abajo me aparecen primero, pero quiero que sea en el orden en que voy seleccionando...
TRAMITAR ESTE ASUNTO, ANALIZAR Y RECOMENDAR.....
This comment was minimized by the moderator on the site
Hi, Gorgelys, Kutools's multi-select drop down list can help you. The items you selected will be in the order like you want.
This comment was minimized by the moderator on the site
the code works but won't let me delete can someone please post the new code.
This comment was minimized by the moderator on the site
bonjour,
selon le premier exemple tout fonctionne très bien jusqu'à ce que je verrouille la feuille.
quand la feuille est verrouillée, je n'ai plus le choix multiple !
comment faire ?
merci par avance
This comment was minimized by the moderator on the site
Hi, sorry for that. We will upgrade our feature next version to avoid this problem. Thank you for your feekback.
This comment was minimized by the moderator on the site
Merci bcp
Mais à quand la nouvelle version ?
This comment was minimized by the moderator on the site
Hi, we have updated this version for you, but this is a beta version, please download it from this: https://download.extendoffice.com/downloads/Kutools-for-Excel/beta/26.10/KutoolsforExcelSetup.Inno.exe
If there are any problems, welcome for your feedback.
This comment was minimized by the moderator on the site
Merci,
Je vais la télécharger et essayer.
Bonne journée
This comment was minimized by the moderator on the site
Hi, the new version is in planning, since next version will upgrade multiple features, it may take somewhat time.
This comment was minimized by the moderator on the site
Hi! Como puedo usar este codigo para todo un worksheet y no solo para una pestana?
This comment was minimized by the moderator on the site
Hi, Vero, Kutools for Excel's Multi-select Drop-down List feature suports selecting multiple items from drop down list in the whole worksheet or across workbook, just specify the Specified Scope in the Multi-select Drop-down List Settings dialog.
This comment was minimized by the moderator on the site
How can I do that for the fist formula you provided :) Thanks in advanced!
This comment was minimized by the moderator on the site
Quando quero deletar alguma opção ou todas dá erro. Como posso resolver?
This comment was minimized by the moderator on the site
I am also finding that after selecting multiple items using the updated VBA code, I still cannot clear the cell, it just keeps multiplying.
Does anyone have a solution for this yet?
This comment was minimized by the moderator on the site
Hi, Rusty, the code I have updated for making it more stable. But because the cell is in data validation, blank is out of data validation, the code cannot solve this problem.
This comment was minimized by the moderator on the site
the code works but carries over across all cells and multiplies in the cells and wont allow delete can you assist?
This comment was minimized by the moderator on the site
If I create a sheet with dropdown list using checkboxes, is there a way to share this workbook with this checkboxes feature?
This comment was minimized by the moderator on the site
How would you apply this functionality but making it so that there aren't redundant values? Any help would be appreciated!
This comment was minimized by the moderator on the site
I used this "Select multiple items from drop down list to a cell without repeat"
this is what happened
1. Multiple selections happen without problems.
2. The issue is when i try to edit and remove an option. There is no way for me to remove an option. it keeps multiplying.
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