hadoan-pap
Thành viên tiêu biểu

- Tham gia
- 8/7/15
- Bài viết
- 461
- Được thích
- 20
Dear all,
Rất mong các bạn xem và kiểm tra giúp mình đoạn code sau mình đang để ở sự kiện Worksheet_Change . Mỗi lần click lên cell nhập xong data thì nó quay mất mấy giây và cảm giác bị chậm rất khó chịu. Rất mong đc các bạn hỗ trợ xem giúp mình đoạn code bị sai hoặc tối ưu như nào để nó nhanh hơn đc k.
Mình xin cảm ơn!
With Application
.Interactive = False
.EnableEvents = False
.ScreenUpdating = False
.Calculation = xlCalculationManual
End With
Dim i As Integer
Dim j As Integer
If Sheet2.Cells(18, 3) <> 0 Then
If Sheet2.Cells(18, 3) < Sheet2.Cells(6, 9) Then
MsgBox "The Plan data could not smaller than AP date.", vbInformation, "Warning......!"
Sheet2.Cells(18, 3).Interior.ColorIndex = 45
Else
Sheet2.Cells(18, 3).Interior.ColorIndex = 2
End If
End If
If Sheet2.Cells(10, 2) = "General Expenditure" And Sheet2.Cells(10, 4) = "Purchase" Then
If Sheet2.Cells(10, 6) = "Tangible Goods" Or Sheet2.Cells(10, 6) = "Intangible Goods" Then
If Sheet2.Cells(25, 8) <> 0 And Sheet2.Cells(25, 8) > 30000000 Then
MsgBox "Check Whether FA Or Not.", vbInformation, "Warning......!"
Sheet2.Cells(25, 8).Interior.ColorIndex = 45
Else
Sheet2.Cells(18, 3).Interior.ColorIndex = 2
End If
End If
End If
If Sheet2.Cells(32, 4) <> 0 And Sheet2.Cells(32, 4) > 2300000 Then
MsgBox "Over Limited Amount.", vbInformation, "Warning...Entertainment Fee Only.!"
Sheet2.Cells(32, 4).Interior.ColorIndex = 45
Else
Sheet2.Cells(32, 4).Interior.ColorIndex = 2
End If
' check chu ky
Call RemoveStraightArrowConnectors
If Sheet2.Cells(10, 2) = "General Expenditure" Or Sheet2.Cells(10, 2) = "Tools & equipments" Then
If IsEmpty(Sheets("Approval sheet Form").Range("H25")) = False Then ' Kiem tra dieu kien H25 co du lieu
If Sheet2.Cells(25, 8) < 250000000 Then
'MsgBox "Over Li.", vbInformation, "test.!"
'Sheets("Sheet1").Range("A1").Copy Destination:=Sheets("2.Approval sheet (PV) (4)").Range("G45") ' Copy dau gach cheo
'Sheet7.Shapes("Straight Connector 1").Copy
'Sheet2.Paste Destination:=Range("G44")
Sheet2.Cells(44, 7).Interior.ColorIndex = 48
Sheet2.Cells(44, 7) = "Not Sign"
Else
Sheet2.Cells(44, 7).Interior.ColorIndex = 2
Sheet2.Cells(44, 7) = " "
End If
End If
End If
If Sheet2.Cells(10, 2) = "General Expenditure" Or Sheet2.Cells(10, 2) = "Tools & equipments" Then
If IsEmpty(Sheets("Approval sheet Form").Range("H25")) = False Then ' Kiem tra dieu kien H25 co du lieu
If Sheet2.Cells(25, 8) < 10000000 Then
'MsgBox "Over Li.", vbInformation, "test.!"
'Sheets("Sheet1").Range("A1").Copy Destination:=Sheets("2.Approval sheet (PV) (4)").Range("G45") ' Copy dau gach cheo
'Sheet7.Shapes("Straight Connector 2").Copy
'Sheet2.Paste Destination:=Range("H44")
'Sheet7.Shapes("Straight Connector 3").Copy
'Sheet2.Paste Destination:=Range("I44")
Sheet2.Cells(44, 8).Interior.ColorIndex = 48
Sheet2.Cells(44, 8) = "Not Sign"
Sheet2.Cells(44, 9).Interior.ColorIndex = 48
Sheet2.Cells(44, 9) = "Not Sign"
Else
Sheet2.Cells(44, 8).Interior.ColorIndex = 2
Sheet2.Cells(44, 8) = " "
Sheet2.Cells(44, 9).Interior.ColorIndex = 2
Sheet2.Cells(44, 9) = " "
End If
End If
End If
For i = 66 To 100
If Sheet2.Cells(16, 2) = Sheet5.Cells(i, 2) Then
Sheet2.Cells(16, 3) = Sheet5.Cells(i, 3)
End If
If Sheet2.Cells(16, 7) = Sheet5.Cells(i, 2) Then
Sheet2.Cells(16, 8) = Sheet5.Cells(i, 3)
End If
Next i
With Application
.Interactive = True
.EnableEvents = True
.ScreenUpdating = True
.Calculation = xlCalculationAutomatic
End With
Rất mong các bạn xem và kiểm tra giúp mình đoạn code sau mình đang để ở sự kiện Worksheet_Change . Mỗi lần click lên cell nhập xong data thì nó quay mất mấy giây và cảm giác bị chậm rất khó chịu. Rất mong đc các bạn hỗ trợ xem giúp mình đoạn code bị sai hoặc tối ưu như nào để nó nhanh hơn đc k.
Mình xin cảm ơn!
With Application
.Interactive = False
.EnableEvents = False
.ScreenUpdating = False
.Calculation = xlCalculationManual
End With
Dim i As Integer
Dim j As Integer
If Sheet2.Cells(18, 3) <> 0 Then
If Sheet2.Cells(18, 3) < Sheet2.Cells(6, 9) Then
MsgBox "The Plan data could not smaller than AP date.", vbInformation, "Warning......!"
Sheet2.Cells(18, 3).Interior.ColorIndex = 45
Else
Sheet2.Cells(18, 3).Interior.ColorIndex = 2
End If
End If
If Sheet2.Cells(10, 2) = "General Expenditure" And Sheet2.Cells(10, 4) = "Purchase" Then
If Sheet2.Cells(10, 6) = "Tangible Goods" Or Sheet2.Cells(10, 6) = "Intangible Goods" Then
If Sheet2.Cells(25, 8) <> 0 And Sheet2.Cells(25, 8) > 30000000 Then
MsgBox "Check Whether FA Or Not.", vbInformation, "Warning......!"
Sheet2.Cells(25, 8).Interior.ColorIndex = 45
Else
Sheet2.Cells(18, 3).Interior.ColorIndex = 2
End If
End If
End If
If Sheet2.Cells(32, 4) <> 0 And Sheet2.Cells(32, 4) > 2300000 Then
MsgBox "Over Limited Amount.", vbInformation, "Warning...Entertainment Fee Only.!"
Sheet2.Cells(32, 4).Interior.ColorIndex = 45
Else
Sheet2.Cells(32, 4).Interior.ColorIndex = 2
End If
' check chu ky
Call RemoveStraightArrowConnectors
If Sheet2.Cells(10, 2) = "General Expenditure" Or Sheet2.Cells(10, 2) = "Tools & equipments" Then
If IsEmpty(Sheets("Approval sheet Form").Range("H25")) = False Then ' Kiem tra dieu kien H25 co du lieu
If Sheet2.Cells(25, 8) < 250000000 Then
'MsgBox "Over Li.", vbInformation, "test.!"
'Sheets("Sheet1").Range("A1").Copy Destination:=Sheets("2.Approval sheet (PV) (4)").Range("G45") ' Copy dau gach cheo
'Sheet7.Shapes("Straight Connector 1").Copy
'Sheet2.Paste Destination:=Range("G44")
Sheet2.Cells(44, 7).Interior.ColorIndex = 48
Sheet2.Cells(44, 7) = "Not Sign"
Else
Sheet2.Cells(44, 7).Interior.ColorIndex = 2
Sheet2.Cells(44, 7) = " "
End If
End If
End If
If Sheet2.Cells(10, 2) = "General Expenditure" Or Sheet2.Cells(10, 2) = "Tools & equipments" Then
If IsEmpty(Sheets("Approval sheet Form").Range("H25")) = False Then ' Kiem tra dieu kien H25 co du lieu
If Sheet2.Cells(25, 8) < 10000000 Then
'MsgBox "Over Li.", vbInformation, "test.!"
'Sheets("Sheet1").Range("A1").Copy Destination:=Sheets("2.Approval sheet (PV) (4)").Range("G45") ' Copy dau gach cheo
'Sheet7.Shapes("Straight Connector 2").Copy
'Sheet2.Paste Destination:=Range("H44")
'Sheet7.Shapes("Straight Connector 3").Copy
'Sheet2.Paste Destination:=Range("I44")
Sheet2.Cells(44, 8).Interior.ColorIndex = 48
Sheet2.Cells(44, 8) = "Not Sign"
Sheet2.Cells(44, 9).Interior.ColorIndex = 48
Sheet2.Cells(44, 9) = "Not Sign"
Else
Sheet2.Cells(44, 8).Interior.ColorIndex = 2
Sheet2.Cells(44, 8) = " "
Sheet2.Cells(44, 9).Interior.ColorIndex = 2
Sheet2.Cells(44, 9) = " "
End If
End If
End If
For i = 66 To 100
If Sheet2.Cells(16, 2) = Sheet5.Cells(i, 2) Then
Sheet2.Cells(16, 3) = Sheet5.Cells(i, 3)
End If
If Sheet2.Cells(16, 7) = Sheet5.Cells(i, 2) Then
Sheet2.Cells(16, 8) = Sheet5.Cells(i, 3)
End If
Next i
With Application
.Interactive = True
.EnableEvents = True
.ScreenUpdating = True
.Calculation = xlCalculationAutomatic
End With