EXCEL TOOLS
Excel Add-ins ที่พัฒนาโดยคุณสันติพงศ์ ณสุย (MVP Excel 2010-2020) ด้วยภาษา C# เพื่อแก้ไขปัญหาไฟล์ใหญ่ คำนวณนาน ทำงานช้า จัดการข้อมูลต่าง ๆ ที่ทำงานประจำวันได้อย่างสะดวกรวดเร็ว สนใจคลิกไปดูได้ที่นี่ครับ => Excel Tools
Excel Add-ins ที่พัฒนาโดยคุณสันติพงศ์ ณสุย (MVP Excel 2010-2020) ด้วยภาษา C# เพื่อแก้ไขปัญหาไฟล์ใหญ่ คำนวณนาน ทำงานช้า จัดการข้อมูลต่าง ๆ ที่ทำงานประจำวันได้อย่างสะดวกรวดเร็ว สนใจคลิกไปดูได้ที่นี่ครับ => Excel Tools
[code]
และปิดด้วย [/code]
ตัวอย่างเช่น [code]dim r as range[/code]
เพื่อให้แตกต่างจากข้อความทั่วไป สะดวกในการอ่านและทดสอบ (คลิกเพื่อดูตัวอย่าง)If Target.Address <> [b2].Address or Target.Address <> [b4].Address Thensnasui wrote: กรณี B2 หรือ B4 สามารถใช้ Or เข้ามาช่วยได้ครับ การอ้างอิงตามลักษณะที่ถามมานั้นเหมือนกันครับ
If Target.Address <> [b2].Address And Target.Address <> [b4].Address Then
Code: Select all
If Target.Address <> [C7].Address And Target.Address <> [C12].Address Then
Application.EnableEvents = True
Exit Sub
เดิมที Code นั้นใช้ร่วมกับ Validation ก็เลยเป็นการตรวจสอบว่าเป็น Validation Type ใด เช่น ตัวเลข วันที่ สูตร เป็นต้น ดูเพิ่มเติมที่นี่ครับ Validation.TypeDhitiBank wrote:2016-11-21 15_33_40-Microsoft Visual Basic for Applications - combo box.xlsm [break] - [Sheet1 (Code.png
อาจารย์ครับrange.Validation.Type
เป็นการเช็คอะไรครับ ทำไมผมลองคีย์ใน immediate window เพื่อดูค่ากลับแสดงค่าผิดพลาดว่า "Application-defined of Object-defined error" ครับ
Code: Select all
Private Sub Worksheet_Selectionchange(ByVal Target As Range)
Dim xStr As String
Dim xCombox As OLEObject
Application.EnableEvents = False
Set xCombox = ActiveSheet.OLEObjects("TempCombo")
With xCombox
.ListFillRange = ""
.LinkedCell = ""
.Visible = False
.Top = Target.Top
End With
If InStr("$C$7$C$12", Target.Address) = 0 Then
Application.EnableEvents = True
Exit Sub
End If
xStr = "Sheet1!J2:J51"
With xCombox
.Visible = True
.Left = Target.Left
.Top = Target.Top
.Width = Target.Width + 5
.Height = Target.Height + 5
.ListFillRange = xStr
.LinkedCell = Target.Address
End With
xCombox.Activate
Me.TempCombo.DropDown
Application.EnableEvents = True
End Sub
Code: Select all
"Other code"
If InStr("$C$7$C$12$C$17", Target.Address) = 0 Then
Application.EnableEvents = True
Exit Sub
End If
xStr = "Sheet1!J2:J51"
With xCombox
.Visible = True
.Left = Target.Left
.Top = Target.Top
.Width = Target.Width + 5
.Height = Target.Height + 5
.ListFillRange = xStr
.LinkedCell = Target.Address
End With
xCombox.Activate
Me.TempCombo.DropDown
Application.EnableEvents = True
If InStr("$C$7", Target.Address) = 0 Then
Application.EnableEvents = True
Exit Sub
End If
xStr = "Sheet1!H2:H3"
With xCombox
.Visible = True
.Left = Target.Left
.Top = Target.Top
.Width = Target.Width + 5
.Height = Target.Height + 5
.ListFillRange = xStr
.LinkedCell = Target.Address
End With
xCombox.Activate
Me.TempCombo.DropDown
Application.EnableEvents = True
If InStr("$C$17", Target.Address) = 0 Then
Application.EnableEvents = True
Exit Sub
End If
xStr = "Sheet1!G2:G10"
With xCombox
.Visible = True
.Left = Target.Left
.Top = Target.Top
.Width = Target.Width + 5
.Height = Target.Height + 5
.ListFillRange = xStr
.LinkedCell = Target.Address
End With
xCombox.Activate
Me.TempCombo.DropDown
Application.EnableEvents = True
End Sub
xStr = "Sheet1!J2:J51"
Code: Select all
If target.address = "$C$7" then
xStr = "Sheet1!H2:H13"
elseif target.address = "$C$12" then
xStr = "Sheet1!J2:J51"
elseif target.address = "$C$17" then
xStr = "Sheet1!G2:G10"
end if
Code: Select all
If target.address = "$C$7" then
xStr = "Sheet1!H2:H13"
elseif target.address = "$C$12" then
xStr = "Sheet1!J2:J51"
elseif target.address = "$C$17" then
xStr = "Sheet1!G2:G10"
end if
ใช่ครับ ผมคีย์ตกไปครับsakajohn wrote:ตรง $C$12" กับ $C$17" ต้องเพิ่ม " เข้าไปข้างหน้าด้วยใช่ไหมครับ
ขอบคุณอาจารย์มากครับsnasui wrote:เดิมที Code นั้นใช้ร่วมกับ Validation ก็เลยเป็นการตรวจสอบว่าเป็น Validation Type ใด เช่น ตัวเลข วันที่ สูตร เป็นต้น ดูเพิ่มเติมที่นี่ครับ Validation.TypeDhitiBank wrote:2016-11-21 15_33_40-Microsoft Visual Basic for Applications - combo box.xlsm [break] - [Sheet1 (Code.png
อาจารย์ครับrange.Validation.Type
เป็นการเช็คอะไรครับ ทำไมผมลองคีย์ใน immediate window เพื่อดูค่ากลับแสดงค่าผิดพลาดว่า "Application-defined of Object-defined error" ครับ
สามารถทดสอบโดยการสร้าง Data Validation ไว้ที่เซลล์ใด ๆ แล้วใช้ Immediate Windows เช็คเพื่อดูผลลัพธ์ครับ