บันทึกข้อมูล VBA
Posted: Thu Mar 12, 2015 5:36 pm
เมื่อกดปุ่ม สมัครสมาชิก แล้วกรอกข้อมูลเสร็จกดตกลง ข้อมูลจะลงไปตารางข้างล่าง แต่ต้องการให้ข้อมูลลงในตารางข้างบนต้องแก้อย่างไรครับ
Code: Select all
Private Sub CommandButton1_Click()
Dim irow As Long
Dim ws As Worksheet
Set ws = Worksheets("sheet1")
'find first empty row in database
irow = ws.Cells(Rows.Count, 2) _
.End(xlUp).Offset(1, 0).Row
'Check for Id
If Trim(Me.TextBox1.Value) = "" Then
Me.TextBox1.SetFocus
MsgBox "¡ÃسҡÃÍ¡¢éÍÁÙÅ"
Exit Sub
End If
'copy the data to the database
ws.Cells(irow, 2).Value = Me.TextBox1.Value
ws.Cells(irow, 3).Value = Me.TextBox2.Value
'Clear the data
Me.TextBox1.Value = ""
Me.TextBox2.Value = ""
Me.TextBox1.SetFocus
End Sub