Trong công việc kiểm kê tiền thủ quỹ thường phải phân loại và tính toán tiền quỹ và một công việc khác liên quan đến kiểm tiền. Sẵn sử dụng bảng tính Excel để tạo 1 tiện ích tính tiền cực kỳ nhỏ gọn và qua bài viết này các bạn sẽ tự thiết kế riêng cho mình một tiện ích tính tiền nhỏ và đẹp.
Nội dung và các bước tiến hành tạo Máy tính tiền bằng VBA Excel
Bước 1: Hiện thị tab developer - enable developer tab Excel
Tab Developer (Nhà phát triển) cho phép bạn truy cập nhanh vào một số tính năng và chức năng nâng cao hơn có sẵn trong Excel như Macro, VBA và Bổ trợ. Theo mặc định, tab Nhà phát triển bị ẩn, nhưng việc bỏ qua nó rất nhanh chóng và dễ dàng và tôi đã phác thảo các bước bên dưới.
- Click phải chuột tại vị trị tab trống chọn Customize the Ribbon.
- Tích chọn Developer như hình dưới- Và tab Developer đã sẵn cho bạn dùng
Bước 2: Mở trình soạn VBA (Atl +F11)
- Tạo UserForm
- Vẽ các Textbox và Label và nút điều khiển Combobox
Code VBA
- Bạn phải đặt các textbox
- Nút Cobobox "Tính Toán"
Private Sub CommandButton2_Click()
If Me.txt500 = "" Then Me.txt500 = 0
If Me.txt500 >= 0 Then Me.tongtxt500 = Format(Me.txt500 * 500000, "#,##0")
If Me.txt200 = "" Then Me.txt200 = 0
If Me.txt200 >= 0 Then Me.tongtxt200 = Format(Me.txt200 * 200000, "#,##0")
If Me.txt100 = "" Then Me.txt100 = 0
If Me.txt100 >= 0 Then Me.tongtxt100 = Format(Me.txt100 * 100000, "#,##0")
If Me.txt50 = "" Then Me.txt50 = 0
If Me.txt50 >= 0 Then Me.tongtxt50 = Format(Me.txt50 * 50000, "#,##0")
If Me.txt20 = "" Then Me.txt20 = 0
If Me.txt20 >= 0 Then Me.tongtxt20 = Format(Me.txt20 * 20000, "#,##0")
If Me.txt10 = "" Then Me.txt10 = 0
If Me.txt10 >= 0 Then Me.tongtxt10 = Format(Me.txt10 * 10000, "#,##0")
If Me.txt5 = "" Then Me.txt5 = 0
If Me.txt5 >= 0 Then Me.tongtxt5 = Format(Me.txt5 * 5000, "#,##0")
If Me.txt2 = "" Then Me.txt2 = 0
If Me.txt2 >= 0 Then Me.tongtxt2 = Format(Me.txt2 * 2000, "#,##0")
If Me.txt1 = "" Then Me.txt1 = 0
If Me.txt1 >= 0 Then Me.tongtxt1 = Format(Me.txt1 * 1000, "#,##0")
If Me.txt005 = "" Then Me.txt005 = 0
If Me.txt005 >= 0 Then Me.tongtxt05 = Format(Me.txt005 * 500, "#,##0")
Me.txt_tongcong = Format(Me.txt500 * 500000 + Me.txt200 * 200000 _
+ Me.txt100 * 100000 + Me.txt50 * 50000 + Me.txt20 * 20000 _
+ Me.txt10 * 10000 + Me.txt5 * 5000 + Me.txt2 * 2000 _
+ Me.txt1 * 1000 + Me.txt005 * 500, "#,##0VND")
End Sub
- Nút Cobobox "Thoát"
Private Sub cbx_thoat_Click()
Unload MAYTINHTIEN
End Sub
- Chỉ cho phép nhập dữ liệu là số
'chi nhan du lieu la so
Private Sub txt500_KeyPress(ByVal KeyAscii As MSForms.ReturnInteger)
If KeyAscii > Asc("9") Or KeyAscii < Asc("0") Then
If KeyAscii = Asc("-") Then
If InStr(1, Me.txt500.Text, "-") > 0 Or _
Me.txt500.SelStart > 0 Then KeyAscii = 0
ElseIf KeyAscii = Asc(".") Then
If InStr(1, Me.txt500.Text, ".") > 0 Then KeyAscii = 0
Else
KeyAscii = 0
End If
End If
End Sub
Private Sub txt200_KeyPress(ByVal KeyAscii As MSForms.ReturnInteger)
If KeyAscii > Asc("9") Or KeyAscii < Asc("0") Then
If KeyAscii = Asc("-") Then
If InStr(1, Me.txt200.Text, "-") > 0 Or _
Me.txt200.SelStart > 0 Then KeyAscii = 0
ElseIf KeyAscii = Asc(".") Then
If InStr(1, Me.txt200.Text, ".") > 0 Then KeyAscii = 0
Else
KeyAscii = 0
End If
End If
End Sub
Private Sub txt100_KeyPress(ByVal KeyAscii As MSForms.ReturnInteger)
If KeyAscii > Asc("9") Or KeyAscii < Asc("0") Then
If KeyAscii = Asc("-") Then
If InStr(1, Me.txt100.Text, "-") > 0 Or _
Me.txt100.SelStart > 0 Then KeyAscii = 0
ElseIf KeyAscii = Asc(".") Then
If InStr(1, Me.txt100.Text, ".") > 0 Then KeyAscii = 0
Else
KeyAscii = 0
End If
End If
End Sub
Private Sub txt50_KeyPress(ByVal KeyAscii As MSForms.ReturnInteger)
If KeyAscii > Asc("9") Or KeyAscii < Asc("0") Then
If KeyAscii = Asc("-") Then
If InStr(1, Me.txt50.Text, "-") > 0 Or _
Me.txt50.SelStart > 0 Then KeyAscii = 0
ElseIf KeyAscii = Asc(".") Then
If InStr(1, Me.txt50.Text, ".") > 0 Then KeyAscii = 0
Else
KeyAscii = 0
End If
End If
End Sub
Private Sub txt20_KeyPress(ByVal KeyAscii As MSForms.ReturnInteger)
If KeyAscii > Asc("9") Or KeyAscii < Asc("0") Then
If KeyAscii = Asc("-") Then
If InStr(1, Me.txt20.Text, "-") > 0 Or _
Me.txt20.SelStart > 0 Then KeyAscii = 0
ElseIf KeyAscii = Asc(".") Then
If InStr(1, Me.txt20.Text, ".") > 0 Then KeyAscii = 0
Else
KeyAscii = 0
End If
End If
End Sub
Private Sub txt10_KeyPress(ByVal KeyAscii As MSForms.ReturnInteger)
If KeyAscii > Asc("9") Or KeyAscii < Asc("0") Then
If KeyAscii = Asc("-") Then
If InStr(1, Me.txt10.Text, "-") > 0 Or _
Me.txt10.SelStart > 0 Then KeyAscii = 0
ElseIf KeyAscii = Asc(".") Then
If InStr(1, Me.txt10.Text, ".") > 0 Then KeyAscii = 0
Else
KeyAscii = 0
End If
End If
End Sub
Private Sub txt5_KeyPress(ByVal KeyAscii As MSForms.ReturnInteger)
If KeyAscii > Asc("9") Or KeyAscii < Asc("0") Then
If KeyAscii = Asc("-") Then
If InStr(1, Me.txt5.Text, "-") > 0 Or _
Me.txt5.SelStart > 0 Then KeyAscii = 0
ElseIf KeyAscii = Asc(".") Then
If InStr(1, Me.txt5.Text, ".") > 0 Then KeyAscii = 0
Else
KeyAscii = 0
End If
End If
End Sub
Private Sub txt2_KeyPress(ByVal KeyAscii As MSForms.ReturnInteger)
If KeyAscii > Asc("9") Or KeyAscii < Asc("0") Then
If KeyAscii = Asc("-") Then
If InStr(1, Me.txt2.Text, "-") > 0 Or _
Me.txt2.SelStart > 0 Then KeyAscii = 0
ElseIf KeyAscii = Asc(".") Then
If InStr(1, Me.txt2.Text, ".") > 0 Then KeyAscii = 0
Else
KeyAscii = 0
End If
End If
End Sub
Private Sub txt1_KeyPress(ByVal KeyAscii As MSForms.ReturnInteger)
If KeyAscii > Asc("9") Or KeyAscii < Asc("0") Then
If KeyAscii = Asc("-") Then
If InStr(1, Me.txt1.Text, "-") > 0 Or _
Me.txt1.SelStart > 0 Then KeyAscii = 0
ElseIf KeyAscii = Asc(".") Then
If InStr(1, Me.txt1.Text, ".") > 0 Then KeyAscii = 0
Else
KeyAscii = 0
End If
End If
End Sub
Private Sub txt005_KeyPress(ByVal KeyAscii As MSForms.ReturnInteger)
If KeyAscii > Asc("9") Or KeyAscii < Asc("0") Then
If KeyAscii = Asc("-") Then
If InStr(1, Me.txt005.Text, "-") > 0 Or _
Me.txt005.SelStart > 0 Then KeyAscii = 0
ElseIf KeyAscii = Asc(".") Then
If InStr(1, Me.txt005.Text, ".") > 0 Then KeyAscii = 0
Else
KeyAscii = 0
End If
End If
End Sub
Tạo nút gọi máy tính tiền
Vậy là xong, chúc các bạn thành công!
0 Nhận xét
Vui lòng viết comment Tiếng Việt có dấu.
Emoji- Bạn có thể gửi mail trực tiếp qua địa chỉ: nhatthienkt.s@gmail.com
- Nhận xét không hỗ trợ cho người dùng ẩn danh
- Lưu ý những nhận xét với mục đích backlink không liên quan đến nội dung bài viết sẽ bị xóa bỏ
- Bạn muốn theo dõi cập nhật trả lời sớm nhất từ adm vui lòng tick vào ô "Thông báo cho tôi" rồi xuất bản nhận xét của mình.