允许 Select 在同一 sheet 的多个列中应用在 Excel 中的所有内容

Allow Select all that Apply in Excel in Multiple Columns on the same sheet

我正在 Excel 中创建一个 activity 跟踪器。我希望能够从同一 sheet.

的两个单独列中的下拉列表中“Select 所有适用项”

我正在为一列使用此 VBA 代码:

Private Sub Worksheet_Change(ByVal Target As Range)

'Code by Sumit Bansal from https://trumpexcel.com
' To make mutliple selections in a Drop Down List in Excel

Dim Oldvalue As String
Dim Newvalue As String

On Error GoTo Exitsub
If Target.Column = 6 Then
    If Target.SpecialCells(xlCellTypeAllValidation) Is Nothing Then
        GoTo Exitsub
    Else: If Target.Value = "" Then GoTo Exitsub Else
        Application.EnableEvents = False
        Newvalue = Target.Value
        Application.Undo
        Oldvalue = Target.Value
        If Oldvalue = "" Then
            Target.Value = Newvalue
        Else
            Target.Value = Oldvalue & ", " & Newvalue
        End If
    End If
End If
Application.EnableEvents = True
Exitsub:
Application.EnableEvents = True
End Sub

我在网上找到了这段代码,并将其修改为应用于所有第 6 列而不是一个单元格。

我希望这适用于 sheet 上的三列,第 1、6 和 9 列。我想这是通过在我的 If Target.Column = 6 语句下方的某处添加 Else 语句来实现的。

尝试回答您的问题,您可以更改以下 If 语句:

If Target.Column = 6 Then

进入

If Target.Column = 1 Or Target.Column = 6 Or Target.Column = 9 Then