เรียน อาจารย์
ผมได้ปรับปรุง Code บางส่วน จนสามารถลงในคอลัมน์ได้ตามต้อง แต่มีบางส่วน ยังคงมีความต้องการและปัญหา ดังนี้
ความต้องการ เมื่อแก้ไขข้อมูลเก่าให้นำข้อมูลวางที่ Row เดิม
ถ้าเพิ่มข้อมูล นำข้อมูลต่อที่Rowล่าง
ผลของ Code
ถ้าแก้ไขเช่น แก้ไข นามสกุลของเลขที่ 1,3,4 จะไม่วางข้อมูลทับของเลขที่เดิม จะนำข้อมูลไปต่อข้างล่าง และไม่แก้ไขตามที่คีย์
1.จากCode ข้างล่างต้องแก้ไขที่ส่วนใด
2.การกำหนดให้ Text แสดงข้อมูลวันเดือนปี เป็นวันเดือนปี
ต้องดำเนินการอย่างไร ครับ
Code: Select all
Private Sub CommandButton1_Click()
Dim rAll As Range, r As Range
Set ws = Worksheets("sheet1")
With ws
Set rAll = .Range("b3", .Range("b" & Rows.Count).End(xlUp))
For Each r In rAll
If CStr(r) = ComboBox1.Text Then
r.Offset(0, 1) = TextBox1.Text
r.Offset(0, 2) = TextBox2.Text
r.Offset(0, 3) = TextBox3.Text
r.Offset(0, 4) = TextBox4.Text
ComboBox1.Text = ""
TextBox1.Text = ""
TextBox2.Text = ""
TextBox3.Text = ""
TextBox4.Text = ""
ElseIf CStr(r) <> ComboBox1.Text Then
'Irow = Sheets("sheet1").Cells(Rows.Count, 1).End(xlUp).Offset(1, 0).Row + 1
Irow = Sheets("sheet1").Cells(Rows.Count, 2).End(xlUp).Offset(1, 0).Row
'ws.Cells(Rows, 1).Value = ComboBox1.Text
ws.Cells(Irow, 2).Value = ComboBox1.Text
ws.Cells(Irow, 3).Value = TextBox1.Text
ws.Cells(Irow, 4).Value = TextBox2.Text
ws.Cells(Irow, 5).Value = TextBox3.Text
ws.Cells(Irow, 6).Value = TextBox4.Text
ComboBox1.Text = ""
TextBox1.Text = ""
TextBox2.Text = ""
TextBox3.Text = ""
TextBox4.Text = ""
Exit For
End If
Next r
End With
End Sub
You do not have the required permissions to view the files attached to this post.