Em làm 1 user form để nhập số liệu vào các ô cụ thể. Tuy nhiên khi chạy code thấy hơi chậm. với lại nhìn code thấy dài quá. e nghĩ có thể rút ngắn lại hơn nhiều và có thể làm cho nhanh hơn. Nhờ các a trên diễn đàn có thể giúp e tối ưu lại code này để e có thể học hỏi thêm. e cảm ơn.
Mã:
Private Sub UserForm_Initialize()
Me.txtChungLoai = Range("AK2")
Me.txt6 = Range("AK4")
Me.txt8 = Range("AL4")
Me.txt10 = Range("AM4")
Me.txt12 = Range("AN4")
Me.txt14 = Range("AO4")
Me.txt16 = Range("AP4")
Me.txt18 = Range("AQ4")
Me.txt20 = Range("AR4")
Me.txt22 = Range("AS4")
Me.txt25 = Range("AT4")
Me.txt28 = Range("AU4")
Me.txt32 = Range("AV4")
Me.txt36 = Range("AW4")
Me.txt40 = Range("AX4")
txt6.Value = Format(txt6.Value, "#,##0.000")
txt8.Value = Format(txt8.Value, "#,##0.000")
txt10.Value = Format(txt10.Value, "#,##0.000")
txt12.Value = Format(txt12.Value, "#,##0.000")
txt14.Value = Format(txt14.Value, "#,##0.000")
txt16.Value = Format(txt16.Value, "#,##0.000")
txt18.Value = Format(txt18.Value, "#,##0.000")
txt20.Value = Format(txt20.Value, "#,##0.000")
txt22.Value = Format(txt22.Value, "#,##0.000")
txt25.Value = Format(txt25.Value, "#,##0.000")
txt28.Value = Format(txt28.Value, "#,##0.000")
txt32.Value = Format(txt32.Value, "#,##0.000")
txt36.Value = Format(txt36.Value, "#,##0.000")
txt40.Value = Format(txt40.Value, "#,##0.000")
End Sub
Private Sub cmdCapNhat_Click()
Application.ScreenUpdating = False
Range("AK2") = txtChungLoai
Range("AK4") = txt6
Range("AL4") = txt8
Range("AM4") = txt10
Range("AN4") = txt12
Range("AO4") = txt14
Range("AP4") = txt16
Range("AQ4") = txt18
Range("AR4") = txt20
Range("AS4") = txt22
Range("AT4") = txt25
Range("AU4") = txt28
Range("AV4") = txt32
Range("AW4") = txt36
Range("AX4") = txt40
Range("AK4:AX4").Select
Selection.NumberFormat = "#,##0.000"
Application.ScreenUpdating = True
End
End Sub
Private Sub cmdThoat_Click()
End
End Sub