假設你的數據在列A:B,其中ROW1爲標題行和你調用一個名爲範圍天然後用鼠標右鍵單擊工作表標籤 - >查看代碼並粘貼下面給出入代碼打開代碼窗口 - >將工作簿保存爲啓用宏的工作簿。
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
If Target.CountLarge > 1 Then Exit Sub
Dim x, dict
Dim i As Long, lr As Long
Dim Rng As Range, Cell As Range
Dim Str As String
lr = Cells(Rows.Count, 1).End(xlUp).Row
Set Rng = Range("A2:A" & lr)
x = Range("Days").Value
Set dict = CreateObject("Scripting.Dictionary")
If Target.Column = 2 And Target.Row > 1 Then
If Target.Offset(0, -1) <> "" Then
For Each Cell In Rng
If Cell <> "" And Cell = Target.Offset(0, -1) Then
If Str = "" Then
Str = Cell.Offset(0, 1).Value
Else
Str = Str & ", " & Cell.Offset(0, 1).Value
End If
End If
Next Cell
For i = 1 To UBound(x, 1)
If InStr(Str, x(i, 1)) = 0 Then
dict.Item(x(i, 1)) = ""
End If
Next i
On Error Resume Next
With Target.Validation
.Delete
.Add Type:=xlValidateList, AlertStyle:=xlValidAlertStop, Operator:= _
xlBetween, Formula1:=Join(dict.keys, ",")
End With
End If
End If
End Sub
所以一旦你選擇B列的單元格,代碼將添加一個下拉列表中排除已選定的特定測試無天。列A中的相應單元格
這隻會覆蓋它,如果他們總是按順序。有時候他們不喜歡'9012',因爲它是在Mon和Wed之間挑選的,所以我最終需要Tue,Sat,Sun。 – Mike
如果您選擇週一下週三,下面的單元格會列出週四 - 週日(名稱週三) – yass