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]
เพื่อให้แตกต่างจากข้อความทั่วไป สะดวกในการอ่านและทดสอบ (คลิกเพื่อดูตัวอย่าง)Code: Select all
Private Sub BTsearch_Click()
On Error Resume Next
'Err.Clear
Dim nRow As String
nRow = Sheet6.Columns(1).Find(txtsearch.Text).Row
If Err.Number = 91 Then
TextBox2.Value = " "
MsgBox "ไม่มีข้อมูล"
End If
TextBox2.Value = Cells(nRow, 2)
End Sub
- ต้องการข้อมูลที่อยู่ใน ชีท EGAS_Data มาแสดงใน Textbox1 เมื่อกรอกข้อมูลแล้วคลิ๊กที่ปุ่ม search เพื่อให้แสดงข้อมูลที่ค้นหาlogic wrote:รูปที่แนบมาไม่เห็นว่าเอาข้อมูลอะไรมาแสดง ช่วยเขียนแจ้งด้วยว่าต้องการข้อมูลอะไรบ้างครับ
ทราบแล้วว่าต้องการเอาข้อมูลในชีต EGAS_Data มาแสดง ข้อมูลอะไรบ้างช่วยเขียนมาให้ละเอียด ในชีตดังกล่าวมีข้อมูลหลายคอลัมน์ครับBenmore wrote:- ต้องการข้อมูลที่อยู่ใน ชีท EGAS_Data มาแสดงใน Textbox1 เมื่อกรอกข้อมูลแล้วคลิ๊กที่ปุ่ม search เพื่อให้แสดงข้อมูลที่ค้นหาlogic wrote:รูปที่แนบมาไม่เห็นว่าเอาข้อมูลอะไรมาแสดง ช่วยเขียนแจ้งด้วยว่าต้องการข้อมูลอะไรบ้างครับ
- ต้องการให้เมื่อเลือกค่าใน combobox กับ checkbox แล้วข้อมูลที่เลือกไปแสดงในTextbox2
Code: Select all
Private Sub BTsearch_Click()
Dim txt As String
On Error Resume Next
'Err.Clear
Dim nRow As String
nRow = Sheet6.Columns(1).Find(txtsearch.Text).Row
If Err.Number = 91 Then
TextBox1.RowSource = "txtsearch.Text"
MsgBox "ไม่มีข้อมูล"
End If
txt = Cells(nRow, 1) & vbCrLf & Cells(nRow, 3) & vbCrLf & Cells(nRow, 8) _
& vbCrLf & Cells(nRow, 13)
TextBox1.Value = txt
End Sub
ทำได้แล้วค่ะ ขอบคุณค่ะsnasui wrote: ตัวอย่าง Code ครับอย่าลืมไปปรับ Property ของ TextBox1 ในหน้าต่าง Propery ให้เป็น Multiline ในส่วนของการเลือก ComboBox และ CheckBox ให้เขียนมาเองก่อน ติดตรงไหนแล้วถามกันต่อครับCode: Select all
Private Sub BTsearch_Click() Dim txt As String On Error Resume Next 'Err.Clear Dim nRow As String nRow = Sheet6.Columns(1).Find(txtsearch.Text).Row If Err.Number = 91 Then TextBox1.RowSource = "txtsearch.Text" MsgBox "ไม่มีข้อมูล" End If txt = Cells(nRow, 1) & vbCrLf & Cells(nRow, 3) & vbCrLf & Cells(nRow, 8) _ & vbCrLf & Cells(nRow, 13) TextBox1.Value = txt End Sub
Code: Select all
Private Sub CheckBox1_Click()
If CheckBox1.Value = True Then
TextBox1.Value = "ชุดหดและเก่าตามสภาพ"
Else
TextBox1.Value = ""
End If
End Sub
Private Sub CheckBox2_Click()
If CheckBox2.Value = True Then
TextBox1.Value = "ชุดเปื่อยขาดเนื่องจากการซัก"
Else
TextBox1.Value = ""
End If
End Sub
Private Sub CheckBox3_Click()
If CheckBox3.Value = True Then
TextBox1.Value = "ชุดขาดตารอยตะเข็บ"
Else
TextBox1.Value = ""
End If
End Sub
Private Sub CheckBox4_Click()
If CheckBox4.Value = True Then
TextBox1.Value = "เดินทางไปทำงานต่างจังหวัด/ต่างประเทศ"
Else
TextBox1.Value = ""
End If
End Sub
Private Sub CheckBox5_Click()
If CheckBox5.Value = True Then
TextBox1.Value = "อื่นๆ"
Else
TextBox1.Value = ""
End If
End Sub
Code: Select all
Private Sub CheckBox1_Click()
If CheckBox1.Value = True Then
TextBox1.Value = "ชุดหดและเก่าตามสภาพ"
Else[attachment=2]ชื่อ1.png[/attachment][attachment=1]ชื่อ2.png[/attachment]
TextBox1.Value = ""
End If
End Sub
Private Sub CheckBox2_Click()
If CheckBox2.Value = True Then
TextBox1.Value = "ชุดเปื่อยขาดเนื่องจากการซัก"
Else
TextBox1.Value = ""
End If
End Sub
Private Sub CheckBox3_Click()
If CheckBox3.Value = True Then
TextBox1.Value = "ชุดขาดตารอยตะเข็บ"
Else
TextBox1.Value = ""
End If
End Sub
Private Sub CheckBox4_Click()
If CheckBox4.Value = True Then
TextBox1.Value = "เดินทางไปทำงานต่างจังหวัด/ต่างประเทศ"
Else
TextBox1.Value = ""
End If
End Sub
Private Sub CheckBox5_Click()
If CheckBox5.Value = True Then
TextBox1.Value = "อื่นๆ"
Else
TextBox1.Value = ""
End If
End Sub
ไฟล์แนบค่ะ คือมีปันหาที่userform1 ตามรูปค่ะ ทำยังไงให้ข้อมูลที่เลือกใน checkbox ขึ้นตามลำดับ ตอจากข้อมูลที่ค้นหาจากปุ่ม search แล้วเมื่อเลือก OK ให้ข้อมูลทั้งหมดไปแสดงใน Userform 2snasui wrote: ไฟล์ Excel ที่แนบมาไม่มี UserForm ตรงกับภาพในโพสต์ก่อนหน้า ควรแนบไฟล์ที่มี Code ล่าสุดพร้อมกับ UserForm ตามภาพครับ
กรณีมีหลาย UserForm ให้แจ้งชื่อ UserForm มาด้วยเสมอจะได้เข้าถึงปัญหาโดยไวครับ
Code: Select all
Private Sub CheckBox1_Click()
If CheckBox1.Value = True Then
TextBox1.Value = TextBox1.Value & vbCrLf & "ชุดหดและเก่าตามสภาพ"
' Else
' TextBox1.Value = ""
End If
End Sub
public strTb1 as string
Code: Select all
Private Sub btok_Click()
strTb1 = Me.TextBox1.Value
Unload Me
UserForm2.Show
End Sub
Code: Select all
Private Sub UserForm_Initialize()
Me.TextBox2.Value = strTb1
Sheet6.Activate
End Sub
Code: Select all
Private Sub CheckBox1_Click()
Dim nRow As String
nRow = Sheet6.Columns(1).Find(txtsearch.Text).Row
If CheckBox1.Value = True Then
TextBox1.Value = TextBox1.Value & vbCrLf & "ชุดหดและเก่าตามสภาพ"
Else
If CheckBox1.Value = False Then
TextBox1.Value = Cells(nRow, 1) & vbCrLf & Cells(nRow, 2) & vbCrLf & Cells(nRow, 8) _
& vbCrLf & Cells(nRow, 13)
Else
End If
End If
End Sub
Code: Select all
Private Sub combobox1_Change()
Dim nRow As String
nRow = Sheet6.Columns(1).Find(txtsearch.Text).Row
If Combobox1.Value = True Then
TextBox1.Value = TextBox1.Value & vbCrLf & "combobox1.Value"
Else
If TextBox1.Value = False Then
TextBox1.Value = Cells(nRow, 1) & vbCrLf & Cells(nRow, 2) & vbCrLf & Cells(nRow, 8) _
& vbCrLf & Cells(nRow, 13)
End If
End If
End Sub
Code: Select all
Private Sub CheckBox1_Click()
Dim nRow As String
nRow = Sheet6.Columns(1).Find(txtsearch.Text).Row
If CheckBox1.Value = True Then
TextBox1.Value = TextBox1.Value & vbCrLf & "ชุดหดและเก่าตามสภาพ"
Else
TextBox1.Value = Replace(TextBox1.Value, vbCrLf & "ชุดหดและเก่าตามสภาพ", "")
End If
End Sub
ทำได้แล้วขอบคุณมากค่ะ แต่ตอนนี้ติดปัญหาตรง Comboboxค่ะ จะทำอย่างไรให้เลือกข้อมูลใน combobox แล้วแสดงค่าใน textbox ค่ะlogic wrote:ลองปรับเป็นแบบนี้ครับ
ถ้าจะให้ต่อกันในแนวนอนไม่ขึ้นบรรทัดใหม่ให้ลบ vbCrLf ที่เกี่ยวข้องทั้งหมดออกไปครับ (bCrLf หมายถึงให้ขึ้นบรรทัดใหม่)Code: Select all
Private Sub CheckBox1_Click() Dim nRow As String nRow = Sheet6.Columns(1).Find(txtsearch.Text).Row If CheckBox1.Value = True Then TextBox1.Value = TextBox1.Value & vbCrLf & "ชุดหดและเก่าตามสภาพ" Else TextBox1.Value = Replace(TextBox1.Value, vbCrLf & "ชุดหดและเก่าตามสภาพ", "") End If End Sub
Code: Select all
Dim nRow As String
nRow = Sheet6.Columns(1).Find(txtsearch.Text).Row
If Combobox1.Value = True Then
TextBox1.Value = TextBox1.Value & vbCrLf & "combobox1.Value"
Else
If TextBox1.Value = False Then
TextBox1.Value = Cells(nRow, 1) & vbCrLf & Cells(nRow, 2) & vbCrLf & Cells(nRow, 8) _
& vbCrLf & Cells(nRow, 13)
End If
End If
End Sub
ไฟล์แนบค่ะ - ติดปัญหาตรง Comboboxค่ะ จะทำอย่างไรให้เลือกข้อมูลใน combobox แล้วแสดงค่าใน textbox ค่ะsnasui wrote: แนบไฟล์ล่าสุดมาดูกัน จะได้ตอบต่อไปจากนั้นครับ
Code: Select all
Private Sub combobox1_Change()
Dim nRow As String
nRow = Sheet6.Columns(1).Find(txtsearch.Text).Row
If Combobox1.Value = True Then
TextBox1.Value = TextBox1.Value & vbCrLf & "combobox1.Value"
Else
If TextBox1.Value = False Then
TextBox1.Value = Cells(nRow, 1) & vbCrLf & Cells(nRow, 2) & vbCrLf & Cells(nRow, 8) _
& vbCrLf & Cells(nRow, 13)
End If
End If
End Sub
Code: Select all
Dim nRow As Integer
nRow = Sheet6.Columns(1).Find(txtsearch.Text).Row
If Combobox1.Value <> "" Then
TextBox1.Value = TextBox1.Value & vbCrLf & Combobox1.Value
Else
If TextBox1.Value = False Then
TextBox1.Value = Cells(nRow, 1) & vbCrLf & Cells(nRow, 2) & vbCrLf & Cells(nRow, 8) _
& vbCrLf & Cells(nRow, 13)
End If
End If