Tách hàm ra để sử dụng nhiều lần (2 người xem)

Liên hệ QC

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

foureye1055

Thành viên mới
Tham gia
9/9/10
Bài viết
19
Được thích
0
Các bạn ơi cho minh hỏi.

Mình viết sự kiện textchange mà mình cần dùng nhiều lần. Mình muốn tách nó ra riêng khỏi TextChange khi nào muốn sữ dụng thì gọi nó vô.

Mã:
Private Sub txtQuatity_Change()
On Error Resume Next
Sheet2.Activate
    If txtGoosID.Text = "" Then
    MsgBox "Input GoodsID"
    ElseIf cmbGoodsName.Text = "" Then
        MsgBox "Chose Goods Name"
        ElseIf cmbCategory.Text = "" Then
            MsgBox "Chose Category"
            ElseIf txtQuatity.Text = "" Then
                MsgBox "Input Quatity"
                Else
                    '=[@Quantity]* VLOOKUP(LEFT([@GoodsID],1),Table5[#All],[@[Category ]]+2,0)
                    txtAmount.Text = txtQuatity.Value * Application.WorksheetFunction.VLookup(Left(cmbGoodsName.Value, 1), Sheets("Sheet2").Range("B18:F23"), cmbCategory.Value + 2, 0)
                    
                    
                    '=[@Amout]*IF(VLOOKUP(LEFT([@GoodsID],1),Table5[#All],5,0)<>"x",VLOOKUP(MID([@GoodsID],2,1)*1,Table6[#All],2,0),0)
                    Dim a As String
                    Dim b As String
                    a = Application.WorksheetFunction.VLookup(Left(cmbGoodsName.Value, 1), Sheets("Sheet2").Range("B18:F23"), 5, 0)
                    b = Application.WorksheetFunction.VLookup(Left(txtGoosID.Value, 1) * 1, Sheets("Sheet2").Range("H18:I22"), 2, 0)
                    If a <> "x" Then
                        txtTax.Value = b * txtAmount.Value
                    ElseIf a = "x" Then
0
                    End If
                    
                    
                    '=[@Amout]-[@Tax]
                    txtRest.Text = txtAmount.Value - txtTax.Value
    End If
End Sub
 
Web KT

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

Back
Top Bottom