Hi RB.
I see your point about the arrays. You will see from my code below that
i'm
inserting "vlookup" formulas, i should put that data into an array as an
initial procedure and then populate the cells from there!?
The thing is i guessed there were a couple of things to spped up my code,
but i couldn't understand why the code would run so quickly with say less
than 8000 lines, but then the performance dropped so substantially /
exponentially after that!
notes: int_Rows is calc'd earlier in the program to find the last row
used.
the Do While loop operates on a cell that contains a recipe name. There
are
many recipe_lines per recipe name. Each time a recipe name changes i want
3
lines to be inserted and be populated with data -some from another
worksheet,
some static.
Thanking you.
n = 3
i = int_Rows + 2
Do While n < i
If Cells(n, 1) <> Cells(n - 1, 1) Then
Rows(n).Insert
Rows(n).Insert
Rows(n).Insert
Previous_Recipe_Code = VBA.CStr(Cells(n - 1, 1))
Current_Recipe_Code = VBA.CStr(Cells(n + 3, 1))
Cells(n, 1) = Previous_Recipe_Code
Cells(n + 1, 1) = Current_Recipe_Code
Cells(n + 2, 1) = Current_Recipe_Code
' Enter Material Output information
Cells(n, 2) = 1
Cells(n, 4) = 980
Cells(n, 5) = 5
Cells(n, 6) = "AR"
Cells(n, 7) = "AR"
Cells(n, 8) = "I"
Cells(n, 9) = VBA.CStr(VBA.Left(Previous_Recipe_Code, 6) &
"MIX")
Cells(n, 10) = "B1"
Cells(n, 13) = 98
Cells(n, 14) = "KG"
Cells(n, 15) = "Y"
Cells(n, 16) = "N"
' enter labor information
Cells(n + 1, 2) = 1
Cells(n + 1, 4) = 960
Cells(n + 1, 5) = 2
Cells(n + 1, 6) = "BL"
Cells(n + 1, 7) = "BL"
Cells(n + 1, 12).Formula = "=vlookup(A" & n + 1 &
",'[compm4.xls]Workings'!$A$2:$D$1500,3,0)"
Cells(n + 1, 18).Formula = "=vlookup(A" & n + 1 &
",'[compm4.xls]Workings'!$A$2:$D$1500,4,0)"
Cells(n + 1, 19) = "R"
Cells(n + 1, 24) = "N"
' Enter Machine Information
Cells(n + 2, 2) = 1
Cells(n + 2, 4) = 970
Cells(n + 2, 5) = 3
Cells(n + 2, 6) = "BO"
Cells(n + 2, 7) = "BO"
Cells(n + 2, 11) = "Machine"
Cells(n + 2, 11).Formula = "=vlookup(A" & n + 2 &
",'[compm4.xls]Workings'!$A$2:$D$1500,2,0)"
Cells(n + 2, 18).Formula = "=vlookup(A" & n + 2 &
",'[compm4.xls]Workings'!$A$2:$D$1500,4,0)"
Cells(n + 2, 19) = "R"
Cells(n + 2, 22) = 0
Cells(n + 2, 23) = "M"
Cells(n + 2, 24) = "N"
n = n + 2
i = i + 3
End If
n = n + 1
Loop
--
John
RB Smissaert said:
Seeing the code will help.
Maybe what can speed this up is putting the data in an array, examine
that
array, write to a second array and at the end write that second array
back
to a sheet.
RBS
Hi,
Can anyone shed any light on the problem i'm having with following
macro.
I have 15k lines of data on a worksheet. My program examines each line
with
an if statement and depending on result inserts 3 new lines, adds 15
cells
of
data for each line, or else moves to the next line.
I have screenupdating set to false, xlcalculation set to xlAutomatic.
This is the part i find curious - if i limit the number of lines of
data
to
<8,000 then the program runs in about 7-8 secs. If i try to run the
program
with the full 15, lines it takes up to 18 mins to run.
Sorry if i've not provided all pertinant info, lemme know if i need to
add
something else.
TIA.