I have here a vba code for my excel. Primary function is to count number of days from a dates and return a number with conditional formatting of a cell. My problem is every time I change a value in a cell it take 2-3 minutes long to respond. I already tried the screenupdating function but with no luck same issue encountered. Below is the source code. Anyone knows how to fix this? Thank you in advance.
Private Sub Worksheet_Change(ByVal Target As Range)
Dim lngNumber As Long
On Error Resume Next
If Target.Address <> "I:J" Then
If Target.Count = 9 Then Exit Sub
If Target.Column = 9 Then
Select Case UCase(Target.Value)
Case "WL"
lngNumber = 5
Case "BL"
lngNumber = 7
Case "CIL", "SL", "TYL"
lngNumber = 15
Case "RAM", "CPR"
lngNumber = 30
Case Else
lngNumber = 0
End Select
End If
End If
If lngNumber < 31 Then
Application.EnableEvents = False
Target.Offset(0, 1).Value = lngNumber
Application.EnableEvents = True
End If
If Target.Count = 1 Then
If Not Intersect(Target, Range("H:J")) Is Nothing Then
Application.EnableEvents = False
Cells(Target.Row, "K").Value = Format(Cells(Target.Row, "H") + Cells(Target.Row, "J"), "MMM DD, YYYY")
Application.EnableEvents = True
End If
End If
If Target.Address <> "L:L" Then
If Target.Count = 1 Then
Application.EnableEvents = False
Cells(Target.Row, "L").Value = (Cells(Target.Row, "K") - (Now()) + 1)
Application.EnableEvents = True
End If
End If
If Target.Address <> "M:H" Then
If Target.Count = 1 Then
Application.EnableEvents = False
Cells(Target.Row, "N").Value = Cells(Target.Row, "M") - Cells(Target.Row, "H")
ActiveSheet.UsedRange.Columns("N").NumberFormat = "General"
Application.EnableEvents = True
End If
End If
End Sub
Bookmarks