VBA การบันทึกข้อมูลจากUserForm ลงsheet แบบขึ้นบันทัดใหม่
Posted: Mon Apr 06, 2020 6:59 pm
สอบถามเรื่อง code VBA ส่งข้อมูลขึ้นบันทัดใหม่ครับ แต่ code ที่ผมลองเขียน มันเป็นแบบแทนที่ข้อมูลไปเลย รบกวนด้วยนะครับ
Code: Select all
Private Sub Save_Click()
Dim irow As Long
Dim ws As Worksheet
Set ws = Worksheets("IP5Resp.")
'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, 3).Value = Me.TextBox1.Value
ws.Cells(irow, 4).Value = Me.TextBox2.Value
ws.Cells(irow, 5).Value = Me.TextBox3.Value
ws.Cells(irow, 6).Value = Me.TextBox4.Value
ws.Cells(irow, 7).Value = Me.TextBox5.Value
ws.Cells(irow, 8).Value = Me.TextBox6.Value
ws.Cells(irow, 9).Value = Me.TextBox7.Value
ws.Cells(irow, 10).Value = Me.TextBox8.Value
ws.Cells(irow, 11).Value = Me.TextBox9.Value
ws.Cells(irow, 12).Value = Me.TextBox10.Value
ws.Cells(irow, 13).Value = Me.TextBox11.Value
ws.Cells(irow, 14).Value = Me.TextBox12.Value
'Clear the data
Me.TextBox1.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.TextBox1.SetFocus
If CommandButton1 Then
IP5.Hide
End If
End Sub