Thứ Bảy, 25 tháng 11, 2017

Chèn code vào Sheet NKC1

Đầu tiên đưa trỏ chuột đến tab sheet "NKC1" click chuột phải giống hình sau :



Chọn View Code bạn thấy hiện ra khung chứa code sheet "NKC1" như sau :



Bạn Chèn vào đoạn code sau :

Private Sub Worksheet_Change(ByVal Target As Range)

On Error Resume Next
Application.EnableEvents = False
Application.ScreenUpdating = False

Dim NKC1 As Worksheet
Set NKC1 = Sheets("NKC1")

Dim cotA As Range
Set cotA = NKC1.Range("a50:a65536")

mataikhoanNodo = Range("c7").Value
mataikhoanCodo = Range("c8").Value


Dim DangKyTK1 As Worksheet
Set DangKyTK1 = Sheets("DangKyTK1")


Dim cot_tk_congno As Range
Set cot_tk_congno = DangKyTK1.Range("c50:c65536")



R_CHANGE = Target.Row
C_CHANGE = Target.Column
If R_CHANGE = 2 And C_CHANGE = 3 Then
Range("c2").Value = UCase(Range("c2").Value)
End If

If R_CHANGE = 7 And C_CHANGE = 3 Then
HS_donghientai = 7
If Application.WorksheetFunction.CountIf(cot_tk_congno, mataikhoanNodo) >= 1 Then
f_doituong.Show
End If
If Application.WorksheetFunction.CountIf(cot_tk_congno, mataikhoanNodo) = 0 Then
Range("f7:g7").Value = ""
End If
End If
If R_CHANGE = 8 And C_CHANGE = 3 Then
HS_donghientai = 8

If Application.WorksheetFunction.CountIf(cot_tk_congno, mataikhoanCodo) >= 1 Then
f_doituong.Show
End If

If Application.WorksheetFunction.CountIf(cot_tk_congno, mataikhoanCodo) = 0 Then
Range("f8:g8").Value = ""

End If

End If


Application.EnableEvents = True
Application.ScreenUpdating = True
End Sub

Private Sub Worksheet_SelectionChange(ByVal Target As Range)
Application.EnableEvents = False

On Error Resume Next

R_CHANGE = Target.Row
C_CHANGE = Target.Column

Application.EnableEvents = True
End Sub

Related Post

Chèn code vào Sheet NKC1
4/ 5
Oleh