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 btnexit_Click()
Unload Rec_frm
End Sub
Private Sub ComboBox1_Change()
If Me.ComboBox1.Value <> "" Then
Dim sh As Worksheet
Set sh = ThisWorkbook.Sheets("DATA2")
Dim i As Integer
i = Application.Match(VBA.CLng(Me.ComboBox1.Value), sh.Range("B:B"), 0)
Me.TextBox2.Value = sh.Range("C" & i).Value
Set sh = ThisWorkbook.Sheets("DATA2")
i = Application.Match(VBA.CLng(Me.ComboBox1.Value), sh.Range("B:B"), 0)
Me.TextBox3.Value = sh.Range("D" & i).Value
Me.TextBox4.Value = sh.Range("E" & i).Value
Me.TextBox5.Value = sh.Range("F" & i).Value
Me.TextBox6.Value = sh.Range("G" & i).Value
Me.TextBox7.Value = sh.Range("H" & i).Value
Me.TextBox8.Value = sh.Range("I" & i).Value
Me.TextBox9.Value = sh.Range("J" & i).Value
Me.TextBox10.Value = sh.Range("K" & i).Value
Me.TextBox11.Value = sh.Range("L" & i).Value
Me.TextBox12.Value = sh.Range("M" & i).Value
Me.TextBox13.Value = sh.Range("N" & i).Value
Me.TextBox14.Value = sh.Range("O" & i).Value
Set sh = ThisWorkbook.Sheets("DATA2")
End If
End Sub
Private Sub CommandButton1_Click()
'''''''''' Check The duplicate EMP ID
Dim sh As Worksheet
Set sh = ThisWorkbook.Sheets("DATA2")
Dim n As Long
n = Application.Match(VBA.CLng(Me.ComboBox2.Value), sh.Range("B:B"), 0)
sh.Range("B" & n).Value = Me.ComboBox2.Value
sh.Range("C" & n).Value = Me.TextBox2.Value
sh.Range("D" & n).Value = Me.TextBox3.Value
sh.Range("E" & n).Value = Me.TextBox4.Value
sh.Range("F" & n).Value = Me.TextBox5.Value
sh.Range("G" & n).Value = Me.TextBox6.Value
sh.Range("H" & n).Value = Me.TextBox7.Value
sh.Range("I" & n).Value = Me.TextBox8.Value
sh.Range("J" & n).Value = Me.TextBox9.Value
sh.Range("K" & n).Value = Me.TextBox10.Value
sh.Range("L" & n).Value = Me.TextBox11.Value
sh.Range("M" & n).Value = Me.TextBox12.Value
sh.Range("N" & n).Value = Me.TextBox13.Value
sh.Range("O" & n).Value = Me.TextBox14.Value
Me.ComboBox2.Value = ""
Me.TextBox2.Value = ""
Me.TextBox3.Value = ""
Me.TextBox4.Value = ""
Me.TextBox5.Value = ""
Me.TextBox6.Value = ""
Me.TextBox7.Value = ""
Me.TextBox8.Value = ""
Me.TextBox9.Value = ""
Me.TextBox10.Value = ""
Me.TextBox11.Value = ""
Me.TextBox12.Value = ""
Me.TextBox13.Value = ""
Me.TextBox14.Value = ""
MsgBox "·Ó¡Òúѹ·Ö¡¢éÍÁÙŨӹǹ˹èÇ¡ÒÃãªé¹éÓÃÒÂà´×͹àÃÕºÃéÍÂáÅéÇ", vbInformation
End Sub
Private Sub CommandButton2_Click()
Me.ComboBox2.Value = ""
Me.TextBox2.Value = ""
Me.TextBox3.Value = ""
Me.TextBox4.Value = ""
Me.TextBox5.Value = ""
Me.TextBox6.Value = ""
Me.TextBox7.Value = ""
Me.TextBox8.Value = ""
Me.TextBox9.Value = ""
Me.TextBox10.Value = ""
Me.TextBox11.Value = ""
Me.TextBox12.Value = ""
Me.TextBox13.Value = ""
Me.TextBox14.Value = ""
End Sub
Private Sub Update_Click()
Recupdate.Show
End Sub
Private Sub UserForm_Activate()
With Me.ComboBox1
End With
Dim sh As Worksheet
Set sh = ThisWorkbook.Sheets("DATA")
Dim i As Integer
Me.ComboBox1.Clear
Me.ComboBox1.AddItem ""
For i = 4 To sh.Range("B" & Application.Rows.Count).End(xlUp).Row
Me.ComboBox1.AddItem sh.Range("B" & i).Value
Next i
End Sub
Private Sub UserForm_QueryClose(Cancel As Integer, _
CloseMode As Integer)
If CloseMode = vbFormControlMenu Then
Cancel = True
MsgBox "¡´»ØèÁ ÍÍ¡ à·èÒ¹Ñ鹤ÃѺ !!!"
End If
End Sub[attachment=0]ระบบบันทึกใหม่.xlsm[/attachment]
Code: Select all
Private Sub CommandButton1_Click()
If Me.TextBox1.Value <> "" Then
Dim irow As Long
Dim ws As Worksheet
Set ws = Worksheets("DATA")
Me.TextBox1.Text = Application.Trim(Me.TextBox1.Text)
'Find first empty row in database
irow = ws.Cells(Rows.Count, 2) _
.End(xlUp).Offset(1, 0).Row
'Copy The Data To The Database
ws.Cells(irow, 2).Value = Me.TextBox1
ws.Cells(irow, 5).Value = Me.TextBox2.Value
ws.Cells(irow, 3).Value = Me.TextBox3.Value
ws.Cells(irow, 4).Value = Me.TextBox4.Value
ws.Cells(irow, 6).Value = Me.TextBox5.Value
ws.Cells(irow, 7).Value = Me.TextBox6.Value
ws.Cells(irow, 8).Value = Me.TextBox7.Value
Unload Me
Add_frrm.Show
Else
MsgBox "¡ÃسÒÃкت×è͹Ó˹éÒ¡è͹¤ÃѺ", vbCritical
End If
End Sub
Code: Select all
Private Sub ComboBox1_Change()
If Me.ComboBox1.Value <> "" Then
Dim sh As Worksheet
Set sh = ThisWorkbook.Sheets("DATA")
Dim i As Integer
i = Application.Match(Me.ComboBox1.Value, sh.Range("B:B"), 0)
Me.TextBox2.Value = sh.Range("E" & i).Value
Me.TextBox3.Value = sh.Range("C" & i).Value
Me.TextBox4.Value = sh.Range("D" & i).Value
Me.TextBox5.Value = sh.Range("F" & i).Value
Me.TextBox6.Value = sh.Range("G" & i).Value
Me.TextBox7.Value = sh.Range("H" & i).Value
End If
End Sub
Code: Select all
Private Sub btnexit_Click()
Unload Update
End Sub
Private Sub ComboBox1_Change()
If Me.ComboBox1.Value <> "" Then
Dim sh As Worksheet
Set sh = ThisWorkbook.Sheets("DATA")
Dim i As Integer
i = Application.Match(Me.ComboBox1.Value, sh.Range("B:B"), 0)
Me.TextBox2.Value = sh.Range("E" & i).Value
Me.TextBox3.Value = sh.Range("C" & i).Value
Me.TextBox4.Value = sh.Range("D" & i).Value
Me.TextBox5.Value = sh.Range("F" & i).Value
Me.TextBox6.Value = sh.Range("G" & i).Value
Me.TextBox7.Value = sh.Range("H" & i).Value
End If
End Sub
Private Sub CommandButton1_Click()
''''''''''Validation''''''''''
If Me.TextBox2.Value = "" Then
MsgBox "¡ÃسÒãÊèª×è͹ÒÁ-Ê¡ØÅ", vbCritical
Exit Sub
End If
If Me.TextBox4.Value = "" Then
MsgBox "¡ÃسÒÃкطÕèÍÂÙè»Ñ¨¨ØºÑ¹", vbCritical
Exit Sub
End If
'''''''''' Check The duplicate EMP ID
Dim sh As Worksheet
Set sh = ThisWorkbook.Sheets("DATA")
Dim n As Long
i = Application.Match(Me.ComboBox1.Value, sh.Range("B:B"), 0)
sh.Unprotect "1234"
sh.Range("B" & n).Value = Me.ComboBox1.Value
sh.Range("E" & n).Value = Me.TextBox2.Value
sh.Range("C" & n).Value = Me.TextBox3.Value
sh.Range("D" & n).Value = Me.TextBox4.Value
sh.Range("F" & n).Value = Me.TextBox5.Value
sh.Range("G" & n).Value = Me.TextBox6.Value
sh.Range("H" & n).Value = Me.TextBox7.Value
sh.Protect "1234"
Me.ComboBox1.Value = ""
Me.TextBox2.Value = ""
Me.TextBox3.Value = ""
Me.TextBox4.Value = ""
Me.TextBox5.Value = ""
Me.TextBox6.Value = ""
Me.TextBox7.Value = ""
MsgBox "ä´é·Ó¡Òúѹ·Ö¡¢éÍÁÙÅ·Õèà»ÅÕè¹á»Å§á¡éä¢áÅéÇ", vbInformation
End Sub
Private Sub CommandButton2_Click()
Me.ComboBox1.Value = ""
Me.TextBox2.Value = ""
Me.TextBox3.Value = ""
Me.TextBox4.Value = ""
Me.TextBox5.Value = ""
Me.TextBox6.Value = ""
Me.TextBox7.Value = ""
End Sub
Private Sub Frame1_Click()
End Sub
Private Sub UserForm_Activate()
With Me.ComboBox1
End With
Dim sh As Worksheet
Set sh = ThisWorkbook.Sheets("DATA")
Dim i As Integer
Me.ComboBox1.Clear
Me.ComboBox1.AddItem ""
For i = 4 To sh.Range("B" & Application.Rows.Count).End(xlUp).Row
Me.ComboBox1.AddItem sh.Range("B" & i).Value
Next i
End Sub
Private Sub UserForm_Click()
Dim sh
End Sub
Private Sub UserForm_QueryClose(Cancel As Integer, _
CloseMode As Integer)
If CloseMode = vbFormControlMenu Then
Cancel = True
MsgBox "¡´»ØèÁ ÍÍ¡ à·èÒ¹Ñ鹤ÃѺ !!!"
End If
End Sub
Private Sub ComboBox1_KeyPress(ByVal KeyAscii As MSForms.ReturnInteger)
KeyAscii = 0
End Sub
Code: Select all
'Other code
Set sh = ThisWorkbook.Sheets("DATA")
Dim i As Integer
If Not IsNumeric(Me.ComboBox1.Text) Then
i = Application.Match(Me.ComboBox1.Value, sh.Range("B:B"), 0)
Else
i = Application.Match(CLng(Me.ComboBox1.Value), sh.Range("B:B"), 0)
End If
'Other code
sh.Range("B" & n).Value = Me.ComboBox1.Value
เพราะค่า n เป็น 0 จึงไม่สามารถเข้าถึง B0 เพราะเซลล์จะเริ่มจาก 1 นั่นคืออย่างน้อยต้องเป็น B1 ไม่ใช่เป็น B0 ครับCode: Select all
Private Sub btnexit_Click()
Unload Update
End Sub
Private Sub ComboBox1_Change()
If Me.ComboBox1.Value <> "" Then
Dim sh As Worksheet
Set sh = ThisWorkbook.Sheets("DATA")
Dim i As Integer
i = Application.Match(Me.ComboBox1.Value, sh.Range("B:B"), 0)
Me.TextBox2.Value = sh.Range("E" & i).Value
Me.TextBox3.Value = sh.Range("C" & i).Value
Me.TextBox4.Value = sh.Range("D" & i).Value
Me.TextBox5.Value = sh.Range("F" & i).Value
Me.TextBox6.Value = sh.Range("G" & i).Value
Me.TextBox7.Value = sh.Range("H" & i).Value
End If
End Sub
Private Sub CommandButton1_Click()
''''''''''Validation''''''''''
If Me.TextBox3.Value = "" Then
MsgBox "กรุณาใส่ชื่อนาม-สกุล", vbCritical
Exit Sub
End If
'''''''''' Check The duplicate EMP ID
Dim sh As Worksheet
Set sh = ThisWorkbook.Sheets("DATA")
Dim n As Long
n = Application.Match(Me.ComboBox1.Value, sh.Range("B:B"), 0)
sh.Unprotect "12345"
sh.Range("B" & n).Value = Me.ComboBox1.Value
sh.Range("E" & n).Value = Me.TextBox2.Value
sh.Range("C" & n).Value = Me.TextBox3.Value
sh.Range("D" & n).Value = Me.TextBox4.Value
sh.Range("F" & n).Value = Me.TextBox5.Value
sh.Range("G" & n).Value = Me.TextBox6.Value
sh.Range("H" & n).Value = Me.TextBox7.Value
sh.Protect "12345"
Me.ComboBox1.Value = ""
Me.TextBox2.Value = ""
Me.TextBox3.Value = ""
Me.TextBox4.Value = ""
Me.TextBox5.Value = ""
Me.TextBox6.Value = ""
Me.TextBox7.Value = ""
MsgBox "ได้ทำการบันทึกข้อมูลที่เปลี่ยนแปลงแก้ไขแล้ว", vbInformation
End Sub
Private Sub CommandButton2_Click()
Me.ComboBox1.Value = ""
Me.TextBox2.Value = ""
Me.TextBox3.Value = ""
Me.TextBox4.Value = ""
Me.TextBox5.Value = ""
Me.TextBox6.Value = ""
Me.TextBox7.Value = ""
End Sub
Private Sub UserForm_Activate()
With Me.ComboBox1
End With
Dim sh As Worksheet
Set sh = ThisWorkbook.Sheets("DATA")
Dim i As Integer
Me.ComboBox1.Clear
Me.ComboBox1.AddItem ""
For i = 4 To sh.Range("B" & Application.Rows.Count).End(xlUp).Row
Me.ComboBox1.AddItem sh.Range("B" & i).Value
Next i
End Sub
Private Sub UserForm_Click()
Dim sh
End Sub
Private Sub UserForm_QueryClose(Cancel As Integer, _
CloseMode As Integer)
If CloseMode = vbFormControlMenu Then
Cancel = True
MsgBox "กดปุ่ม ออก เท่านั้นครับ !!!"
End If
End Sub
Private Sub ComboBox1_KeyPress(ByVal KeyAscii As MSForms.ReturnInteger)
KeyAscii = 0
End Sub
Code: Select all
i = Application.Match(Me.ComboBox1.Value, sh.Range("B:B"), 0)
Code: Select all
i = Me.ComboBox1.ListIndex + 3
Code: Select all
n = Application.Match(Me.ComboBox1.Value, sh.Range("B:B"), 0)
Code: Select all
n = Me.ComboBox1.ListIndex + 3