ใช้codeเดียวกับการค้นหาข้อมูล ซึ่งทำได้อยู่แล้ว ก็คือเมื่อตรวจสอบเจอ ก็เอาข้อมูลแถวนั้นทีละคอลัมน์ ไปใส่ใน Form
การแก้ไขจะกลับกัน เมื่อตรวจสอบเจอเอาข้อมูลใน Formมาใส่ใน cellแทน
ค้นหาข้อมูล ของคุณtorie04 ใช้codeนี้อยู่
Code: Select all
With Worksheets(db_sheet)
.Cells(blank_row, id_col).Value = form1.id_txtbox.Value
.Cells(blank_row, name_col).Value = form1.name_txtbox.Value
.Cells(blank_row, surname_col).Value = form1.surname_txtbox.Value
.Cells(blank_row, sex_col).Value = form1.sex_cbbox.Value
.Cells(blank_row, section_col).Value = form1.Section_txtbox.Value
.Cells(blank_row, Dept_col).Value = form1.Dept_cbbox.Value
End With
พอจะแก้ไขข้อมูลใช้codeนี้แทน
Code: Select all
Worksheets(db_sheet).Cells(data_row, name_col).Value = name_txtbox.Value
Worksheets(db_sheet).Cells(data_row, surname_col).Value = surname_txtbox.Value
Worksheets(db_sheet).Cells(data_row, sex_col).Value = sex_cbbox.Value
Worksheets(db_sheet).Cells(data_row, id_col).Value = id_txtbox.Value
Worksheets(db_sheet).Cells(data_row, section_col).Value = Section_txtbox.Value
Worksheets(db_sheet).Cells(data_row, Dept_col).Value = Dept_cbbox.Value
และการใช้ Do Until ถ้าหาไม่เจอจะค้นทั้งคอลัมน์ทำให้ช้า ควรเพิ่ม ให้หยุดเมื่อถึงข้อมูลแถวสุดท้าย
Code: Select all
lastrow = .Cells(Rows.Count, 1).End(xlUp).Row
Do Until id_check = id_txtbox.Text Or data_row > lastrow
You do not have the required permissions to view the files attached to this post.