Hi everyone,
Recently I started dabbling with VBA to automate some Excel work and got the following script to work. The only problem is that it gets slower when more records are in the source file;
lines |
time (seconds) |
lines/sec |
1200 |
3,14 |
382 |
2400 |
10 |
240 |
4000 |
26,4 |
152 |
This makes me believe I built something that gets slower the bigger the file is. Could anyone give me some pointers as to how to make this perform better? Would be very much appreciated! This is the script:
=====
Application.Calculation = xlCalculationManual
Application.ScreenUpdating = False
Application.EnableEvents = False
Dim sObjectID As String
Dim dStartMaand As Integer
Dim dEndMaand As Integer
Dim nRowNum As Integer
Dim cellRange As Range
Dim nRowSource As Long
Dim x As String
Dim found As Boolean
nRowSource = 2
Do While Not IsEmpty(Sheets(1).Cells(nRowSource, 1))
sObjectID = Sheets(1).Cells(nRowSource, 1)
dStartMaand = Sheets(1).Cells(nRowSource, 8)
dEndMaand = Sheets(1).Cells(nRowSource, 9)
Sheets("Blad2").Select
Range("A2").Select
found = False
Do Until IsEmpty(ActiveCell)
If ActiveCell.Value = sObjectID Then
found = True
Exit Do
End If
ActiveCell.Offset(1, 0).Select
Loop
If found = True Then
nRowNum = ActiveCell.Row
End If
Set cellRange = Range(Cells(nRowNum, (dStartMaand + 2)), Cells(nRowNum, (dEndMaand + 2)))
cellRange.Value = 1
nRowSource = nRowSource + 1
Loop
Application.Calculation = xlCalculationAutomatic
Application.EnableEvents = True
=====
What it does?
In Sheet 1 I have multiple lines per object with a duration in months. In Sheet 2 I have 1 line per object, and the ranges get updated there.
Kind regards