現在、BeforeDoubleClickを使用しているワークシートにコードがあります。このコードは、データ検証式を含むダブルクリックされたセルにコンボボックスを配置します。コンボボックスはこの式を使います。Excel依存のデータ検証ComboBox on Single Click
私はこれが好きですが、データ検証リストが得られるが、コンボボックスに入力してデータ検証オプションのオートコンプリートを取得するオプションもあります。
ワークシート自体に2つのデータ検証領域があります.1つはState用、もう1つはCity用です。市のデータ検証は、州の選択に依存します。
私は実際には、ユーザーが選択を変更するたびにダブルクリックする必要があることを嫌っています。シングルクリックしてポップアップを開いてもいいですね。
ご協力いただきましてありがとうございます。
ワークシートコード: (http://www.contextures.com/xlDataVal11.html#worksから) (((彼らは別のリンク(http://www.contextures.com/xlDataVal14.html)シングルクリックでこれを行う方法を示すがありますが、私は間接=のためにセクションを追加しようとすると、依存データを可能にバリデーション)それdoesntの仕事。))
'==========================
Private Sub Worksheet_BeforeDoubleClick _
(ByVal Target As Range, _
Cancel As Boolean)
Dim str As String
Dim cboTemp As OLEObject
Dim ws As Worksheet
Set ws = ActiveSheet
Set cboTemp = ws.OLEObjects("TempCombo")
On Error Resume Next
With cboTemp
'clear and hide the combo box
.ListFillRange = ""
.LinkedCell = ""
.Visible = False
End With
On Error GoTo errHandler
If Target.Validation.Type = 3 Then
'if the cell contains
'a data validation list
Cancel = True
Application.EnableEvents = False
'get the data validation formula
str = Target.Validation.Formula1
str = Right(str, Len(str) - 1)
'for simple INDIRECT function (English)
' e.g. =INDIRECT(B2)
'will create dependent list of items
If Left(str, 4) = "INDI" Then
lSplit = InStr(1, str, "(")
str = Right(str, Len(str) - lSplit)
str = Left(str, Len(str) - 1)
str = Range(str).Value
End If
With cboTemp
'show the combobox with the list
.Visible = True
.Left = Target.Left
.Top = Target.Top
.Width = Target.Width + 15
.Height = Target.Height + 4
.ListFillRange = str
.LinkedCell = Target.Address
End With
cboTemp.Activate
'open the drop down list automatically
Me.TempCombo.DropDown
End If
errHandler:
Application.EnableEvents = True
Exit Sub
End Sub
'=========================================
Private Sub TempCombo_LostFocus()
With Me.TempCombo
.Top = 10
.Left = 10
.Width = 0
.ListFillRange = ""
.LinkedCell = ""
.Visible = False
.Value = ""
End With
End Sub
'====================================
Private Sub TempCombo_KeyDown(ByVal _
KeyCode As MSForms.ReturnInteger, _
ByVal Shift As Integer)
Select Case KeyCode
Case 9 'Tab
ActiveCell.Offset(0, 1).Activate
Case 13 'Enter
ActiveCell.Offset(1, 0).Activate
Case Else
'do nothing
End Select
End Sub