Giúp tạo nút lệnh (trước, sau, sửa, lưu, tìm) cho form trong Excel (1 người xem)

  • Thread starter Thread starter Thaiduc
  • Ngày gửi Ngày gửi
Liên hệ QC

Người dùng đang xem chủ đề này

Thaiduc

Thành viên hoạt động
Tham gia
13/3/07
Bài viết
118
Được thích
6
Giúp mình tạo các nút:
Trước: Xem lại dữ liệu đã nhập
Sau: Xem lại dữ liệu đã nhập hoặc tiếp tục nhập mới
Sửa: Xem lại dữ liệu đã nhập và sửa, sau khi sửa thì nhấn nút lưu những thay đổi với dữ liệu đó ngay hàng dữ liệu đó, không thêm hàng mới
Lưu: Sau khi sửa xong mới hiện và sử dụng nút "Lưu", bình thường thì khi nhập xong nhấn nút "Nhập"
Xin gửi kèm theo File. Mong các anh, chi giúp
 

File đính kèm

hello bạn

không biết bạn đã giải quyết vấn đề này xong chưa, tôi thi mới tập tành vba thôi,
gửi bạn tham khảo.
để dể tìm số liệu bạn nên tạo tiêu đề ở dòng đầu tiên của sheet data và sử dụng "SoGiay" làm key trong quá trình tìm kiếm, nếu bạn đổi key thì hãy đổi lại lệnh trong code
bạn hãy tạo thêm 2 CommandButton cho "Preview" và "Save" rồi chép 2 đạon code này vào cho mỗi button tương ứng nha

Private Sub CommandButton1_Click() ' đoạn code cho button Preview
Dim iRow As Long
Dim ws As Worksheet
Set ws = Worksheets("DATA")

ws.Cells(1, 20) = Me.XSoGiay

If Range("T1").Value = "" Then
MsgBox " NHAP SO GIAY"
Cells(1, 20).Select
Exit Sub
End If

Cells.Select
Selection.AutoFilter
Selection.AutoFilter Field:=1, Criteria1:=Range("T1")

iRow = ws.Cells(Rows.Count, 2) _
.End(xlUp).Offset(1, 0).Row - 1

If ws.Cells(iRow, 1).Value = "SoGiay" Then 'tui sử dụng "SoGiay" làm tiêu đề, nếu bạn sửa thì sửa lại chử này
MsgBox " Ban Nhap Sai So Giay"
Exit Sub
End If

Me.XSoGiay.Value = ws.Cells(iRow, 1).Value
Me.XSoQuyen.Value = ws.Cells(iRow, 2).Value
Me.XHovaTen.Value = ws.Cells(iRow, 3).Value
Me.XGioiTinh.Value = ws.Cells(iRow, 4).Value
Me.XNgaysinh.Value = ws.Cells(iRow, 5).Value
Me.XNoisinhcon.Value = ws.Cells(iRow, 6).Value
Me.XDantoccon.Value = ws.Cells(iRow, 7).Value
Me.XQuoctichcon.Value = ws.Cells(iRow, 8).Value
Me.XHovatencha.Value = ws.Cells(iRow, 9).Value
Me.XDantoccha.Value = ws.Cells(iRow, 10).Value
Me.XQuoctichcha.Value = ws.Cells(iRow, 11).Value
Me.XNamsinhcha.Value = ws.Cells(iRow, 12).Value
Me.XNoiocha.Value = ws.Cells(iRow, 13).Value
Me.XHovaTenme.Value = ws.Cells(iRow, 14).Value
Me.XDantocme.Value = ws.Cells(iRow, 15).Value
Me.XQuoctichme.Value = ws.Cells(iRow, 16).Value
Me.XNamsinhme.Value = ws.Cells(iRow, 17).Value
Me.XNoiome.Value = ws.Cells(iRow, 18).Value


ActiveSheet.AutoFilterMode = False
Range("T1").ClearContents

End Sub

Private Sub CommandButton2_Click() ' đoạn code cho save
Dim iRow As Long
Dim ws As Worksheet
Set ws = Worksheets("DATA")
ws.Cells(1, 20) = Me.XSoGiay
Cells.Select
Selection.AutoFilter
Selection.AutoFilter Field:=1, Criteria1:=Range("T1")
iRow = ws.Cells(Rows.Count, 2) _
.End(xlUp).Offset(1, 0).Row - 1

ws.Cells(iRow, 1).Value = Me.XSoGiay.Value
ws.Cells(iRow, 2).Value = Me.XSoQuyen.Value
ws.Cells(iRow, 3).Value = Me.XHovaTen.Value
ws.Cells(iRow, 4).Value = Me.XGioiTinh.Value
ws.Cells(iRow, 5).Value = Me.XNgaysinh.Value
ws.Cells(iRow, 6).Value = Me.XNoisinhcon.Value
ws.Cells(iRow, 7).Value = Me.XDantoccon.Value
ws.Cells(iRow, 8).Value = Me.XQuoctichcon.Value
ws.Cells(iRow, 9).Value = Me.XHovatencha.Value
ws.Cells(iRow, 10).Value = Me.XDantoccha.Value
ws.Cells(iRow, 11).Value = Me.XQuoctichcha.Value
ws.Cells(iRow, 12).Value = Me.XNamsinhcha.Value
ws.Cells(iRow, 13).Value = Me.XNoiocha.Value
ws.Cells(iRow, 14).Value = Me.XHovaTenme.Value
ws.Cells(iRow, 15).Value = Me.XDantocme.Value
ws.Cells(iRow, 16).Value = Me.XQuoctichme.Value
ws.Cells(iRow, 17).Value = Me.XNamsinhme.Value
ws.Cells(iRow, 18).Value = Me.XNoiome.Value

ActiveSheet.AutoFilterMode = False
Range("T1").ClearContents
ThisWorkbook.Save

End Sub

hy vọng 9dáp ứng được yêu cầu của bạn
 
Upvote 0
Web KT

Bài viết mới nhất

Back
Top Bottom