Hello everybody,
I'm new to this forum and usually I figured out everything myself with just searching this great forum but this problem I have I can't seem to solve.
I have a date calculation. You can enter either a real start/end date, a start/end week number, a start/end month number, a year, a duration in days, a duration and weeks.
Now depending on your input, VBA creates formulas in the respective cells.
The code below worked okay with limited rows but now I have over 200 and it is super slow since the code runs through the all cells starting from the beginning.
I tried working with ActiveCell.Row but without any success. Any help is welcome.
Dim vOldVal
Dim vOldFormula
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
vOldVal = Target.Formula
vOldFormula = Target.Value
End Sub
Private Sub Worksheet_Change(ByVal Target As Range)
On Error Resume Next
Dim oCalcStatus As Variant
Dim Derlig As String
Dim changableRange As Range
With ThisWorkbook.Sheets("Input")
'BEGINNING DATE CHANGE
' Start Day change -- OK reviewed OK
Derlig = .Columns(19).Find("*", , , , , xlPrevious).Row
For i = 14 To Derlig
Set changableRange = Range("S14:S" & i)
If Not Intersect(Target, changableRange) Is Nothing Then
Application.ScreenUpdating = False
oCalcStatus = Application.Calculation
Application.Calculation = xlCalculationManual
Application.enableEvents = False
If Range("Y" & i).Value <> "" Then
Range("W" & i).Formula = "=Y" & i & "-S" & i & "-1"
Range("W" & i).Value = Range("W" & i).Value
Range("V" & i).Formula = "=year(S" & i & ")"
If Range("V" & i).Value = "" Then
Range("V" & i).Value = Range("dfltYear").Value
End If
End If
If Range("W" & i).Value = "" Then
Range("W" & i).Value = Range("dfltDays").Value
End If
Range("T" & i).Formula = "=Weeknum(S" & i & ")"
Range("U" & i).Formula = "=month(S" & i & ")"
Range("V" & i).Formula = "=year(S" & i & ")"
Range("X" & i).Formula = "=ROUNDUP(W" & i & "/7,0)"
'changed, why do we need below?
Range("Y" & i).Formula = "=if(WEEKDAY(S" & i & "+W" & i & ",2)=6,S" & i & "+W" & i & "+1,if(WEEKDAY(S" & i & "+W" & i & ",2)=7,S" & i & "+W" & i & "+1,S" & i & "+W" & i & "))"
'Changed to -1 to reflect 1=1 day
'Range("Y" & i).Formula = "=S" & i & "+W" & i & "-1"
Range("Z" & i).Formula = "=Weeknum(Y" & i & ")"
Range("AA" & i).Formula = "=month(Y" & i & ")"
Range("AB" & i).Formula = "=year(Y" & i & ")"
Application.enableEvents = True
Application.Calculation = oCalcStatus
Application.ScreenUpdating = True
End If
Next
'code continues but to big to post here
End With
End Sub
Bookmarks