snasui.com ยินดีต้อนรับ ยินดีต้อนรับสู่กระดานถามตอบ Excel and VBA และอื่น ๆ ที่เป็นมิตรกับทุกท่าน มีไฟล์แนบมหาศาล ช่วยให้ท่านค้นหาและติดตามศึกษาได้โดยง่าย สมาชิกท่านใดที่ยังไม่ได้ระบุ Version ของ Excel ที่ใช้งานจริง สามารถทำตาม Link นี้เพื่อจะได้รับคำตอบที่ตรงกับ Version ของท่านครับ ระบุ Version ของ Excel
ขอถามเพิ่มหน่อยครับ เนื่องจากรายการใน drop downl list มีจำนวนมาก พิมพ์ตัวอักษรตัวแรกเข้าไปเพื่อให้แสดงเฉพาะข้อความที่เกี่ยวข้องได้เปล่าครับ หรือให้ drop downl list เลื่อนไปอยู่ข้อความที่เกี่ยวข้องก็ได้ครับ ตัวอย่างในรูปที่แนบมาครับ
You do not have the required permissions to view the files attached to this post.
Option Explicit
' Developed by Contextures Inc.
' www.contextures.com
Private Sub TempCombo_KeyDown(ByVal _
KeyCode As MSForms.ReturnInteger, _
ByVal Shift As Integer)
'move to next cell on Enter and Tab
Dim varVal As Variant
On Error Resume Next
'change text value to number, if possible
varVal = --ActiveCell.Value
If IsEmpty(varVal) Then
varVal = ActiveCell.Value
End If
Select Case KeyCode
Case 9 'tab
ActiveCell.Value = varVal
ActiveCell.Offset(0, 1).Activate
Case 13 'enter
ActiveCell.Value = varVal
ActiveCell.Offset(1, 0).Activate
Case Else
'do nothing
End Select
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 Worksheet_BeforeDoubleClick(ByVal Target As Range, Cancel As Boolean)
Dim str As String
Dim cboTemp As OLEObject
Dim ws As Worksheet
Dim wsList As Worksheet
Set ws = ActiveSheet
Set wsList = Sheets("ValidationSample")
Set cboTemp = ws.OLEObjects("TempCombo")
On Error Resume Next
With cboTemp
.ListFillRange = ""
.LinkedCell = ""
.Visible = False
End With
On Error GoTo errHandler
If Target.Validation.Type = 3 Then
Cancel = True
Application.EnableEvents = False
str = Target.Validation.Formula1
str = Right(str, Len(str) - 1)
With cboTemp
.Visible = True
.Left = Target.Left
.Top = Target.Top
.Width = Target.Width + 15
.Height = Target.Height + 5
.ListFillRange = str
.LinkedCell = Target.Address
End With
cboTemp.Activate
End If
errHandler:
Application.EnableEvents = True
Exit Sub
End Sub
You do not have the required permissions to view the files attached to this post.
Private Sub TempCombo_KeyDown(ByVal _
KeyCode As MSForms.ReturnInteger, _
ByVal Shift As Integer)
'move to next cell on Enter and Tab
Dim varVal As Variant
On Error Resume Next
'change text value to number, if possible
varVal = --ActiveCell.Value
If IsEmpty(varVal) Then
varVal = ActiveCell.Value
End If
Select Case KeyCode
Case 9 'tab
If Application.CountIf(Worksheets("ValidationLists").Range("c1:c12"), varVal) > 0 Then
ActiveCell.Value = varVal
ActiveCell.Offset(0, 1).Activate
Else
ActiveCell.ClearContents
MsgBox "Not match.", vbExclamation
End If
Case 13 'enter
If Application.CountIf(Worksheets("ValidationLists").Range("c1:c12"), varVal) > 0 Then
ActiveCell.Value = varVal
ActiveCell.Offset(1, 0).Activate
Else
ActiveCell.ClearContents
MsgBox "Not match.", vbExclamation
End If
Case Else
'do nothing
End Select
End Sub
Option Explicit
' Developed by Contextures Inc.
' www.contextures.com
Private Sub TempCombo_KeyDown(ByVal _
KeyCode As MSForms.ReturnInteger, _
ByVal Shift As Integer)
'move to next cell on Enter and Tab
Dim varVal As Variant
On Error Resume Next
'change text value to number, if possible
varVal = --ActiveCell.Value
If IsEmpty(varVal) Then
varVal = ActiveCell.Value
End If
Select Case KeyCode
Case 9 'tab
If Application.CountIf(Worksheets("ValidationLists").Range("c1:c12"), varVal) > 0 Then
ActiveCell.Value = varVal
ActiveCell.Offset(0, 1).Activate
Else
ActiveCell.ClearContents
MsgBox "Not match.", vbExclamation
End If
Case 13 'enter
If Application.CountIf(Worksheets("ValidationLists").Range("c1:c12"), varVal) > 0 Then
ActiveCell.Value = varVal
ActiveCell.Offset(1, 0).Activate
Else
ActiveCell.ClearContents
MsgBox "Not match.", vbExclamation
End If
Case Else
'do nothing
End Select
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 Worksheet_BeforeDoubleClick(ByVal Target As Range, Cancel As Boolean)
Dim str As String
Dim cboTemp As OLEObject
Dim ws As Worksheet
Dim wsList As Worksheet
Set ws = ActiveSheet
Set wsList = Sheets("ValidationLists")
Set cboTemp = ws.OLEObjects("TempCombo")
On Error Resume Next
With cboTemp
.ListFillRange = ""
.LinkedCell = ""
.Visible = False
End With
On Error GoTo errHandler
If Target.Validation.Type = 3 Then
Cancel = True
Application.EnableEvents = False
str = Target.Validation.Formula1
str = Right(str, Len(str) - 1)
With cboTemp
.Visible = True
.Left = Target.Left
.Top = Target.Top
.Width = Target.Width + 15
.Height = Target.Height + 5
.ListFillRange = str
.LinkedCell = Target.Address
End With
cboTemp.Activate
End If
errHandler:
Application.EnableEvents = True
Exit Sub
End Sub
You do not have the required permissions to view the files attached to this post.