Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 510
Default Excel2000: code too slow

Hi

The code snippet below works too slow. It exports data from one Excel table
(Customer,CustCode, Article, January, ..., December) to new one in different
workbook (CustCode, Article, FirstWorkdayOfMonth, EntryType, CustCode). It
looks like the problem is writing data to new table - writing 12 months data
(12*5 fields) from a row in source table into new table takes ~50 sec. As
the source table has almost 2000 rows, and most of rows have values for all
12 months, it takes 10 hours to generate the new table. (The rest of code
takes next to nothing to run - the code row displaying process info on
status bar was added to check this)

At start I used offset to determine target cells, and suspected this to be
the cause. So I replaced offsets with direct references - but this had no
effect at all.

Can anyone explain me this? Thanks in advance!

....
k = 0
....
If
Workbooks(varSource).Sheets(varSheet).Range("A1"). Offset(i - 1, 1) = varCode
Then
varArticle =
Workbooks(varSource).Sheets(varSheet).Range("A1"). Offset(i - 1, 2)
For j = 1 To 12
If
Workbooks(varSource).Sheets(varSheet).Range("A1"). Offset(i - 1, j + 2) 0
Then
Application.StatusBar = "Code: " & varCode & ",
Article: " & varArticle & ", Month:" & arrMonths(j)

ThisWorkbook.Sheets("Forecast").Range("A" & (k +
1) & ":C" & (k + 1)).NumberFormat = "@"
ThisWorkbook.Sheets("Forecast").Range("D" & (k +
1) & ":E" & (k + 1)).NumberFormat = "General"
ThisWorkbook.Sheets("Forecast").Range("F" & (k +
1)).NumberFormat = "@"
ThisWorkbook.Sheets("Forecast").Range("A" & (k +
1)) = varCode
ThisWorkbook.Sheets("Forecast").Range("B" & (k +
1)) = varArticle
ThisWorkbook.Sheets("Forecast").Range("C" & (k +
1)) = arrMonths(j)
ThisWorkbook.Sheets("Forecast").Range("D" & (k +
1)) = Workbooks(varSource).Sheets(varSheet).Range("A1"). Offset(i - 1, j + 2)
ThisWorkbook.Sheets("Forecast").Range("E" & (k +
1)) = 4
ThisWorkbook.Sheets("Forecast").Range("F" & (k +
1)) = varCode
k = k + 1
End If
Next j
End If
Exit For
End If
....


--
Arvi Laanemets
( My real mail address: arvil<attarkon.ee )


  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 4,339
Default Excel2000: code too slow

Arvi,
I emulated your code by simply selecting 2000 records (to
generate 24000) and it took less than a minute! So maybe my emulation was not
realistic but I cannot understand why it would hours (never mind 10 minutes).

Unless there is reason not to do so, you could format the columns prior to
insert the data rather than in the loop - this speeds things up.

I have Excel 2003 but I don't believe this makes any (significant)
difference over 2000.


If you have file you can send me with all the code, I would willing to test
further.

)


"Arvi Laanemets" wrote:

Hi

The code snippet below works too slow. It exports data from one Excel table
(Customer,CustCode, Article, January, ..., December) to new one in different
workbook (CustCode, Article, FirstWorkdayOfMonth, EntryType, CustCode). It
looks like the problem is writing data to new table - writing 12 months data
(12*5 fields) from a row in source table into new table takes ~50 sec. As
the source table has almost 2000 rows, and most of rows have values for all
12 months, it takes 10 hours to generate the new table. (The rest of code
takes next to nothing to run - the code row displaying process info on
status bar was added to check this)

At start I used offset to determine target cells, and suspected this to be
the cause. So I replaced offsets with direct references - but this had no
effect at all.

Can anyone explain me this? Thanks in advance!

....
k = 0
....
If
Workbooks(varSource).Sheets(varSheet).Range("A1"). Offset(i - 1, 1) = varCode
Then
varArticle =
Workbooks(varSource).Sheets(varSheet).Range("A1"). Offset(i - 1, 2)
For j = 1 To 12
If
Workbooks(varSource).Sheets(varSheet).Range("A1"). Offset(i - 1, j + 2) 0
Then
Application.StatusBar = "Code: " & varCode & ",
Article: " & varArticle & ", Month:" & arrMonths(j)

ThisWorkbook.Sheets("Forecast").Range("A" & (k +
1) & ":C" & (k + 1)).NumberFormat = "@"
ThisWorkbook.Sheets("Forecast").Range("D" & (k +
1) & ":E" & (k + 1)).NumberFormat = "General"
ThisWorkbook.Sheets("Forecast").Range("F" & (k +
1)).NumberFormat = "@"
ThisWorkbook.Sheets("Forecast").Range("A" & (k +
1)) = varCode
ThisWorkbook.Sheets("Forecast").Range("B" & (k +
1)) = varArticle
ThisWorkbook.Sheets("Forecast").Range("C" & (k +
1)) = arrMonths(j)
ThisWorkbook.Sheets("Forecast").Range("D" & (k +
1)) = Workbooks(varSource).Sheets(varSheet).Range("A1"). Offset(i - 1, j + 2)
ThisWorkbook.Sheets("Forecast").Range("E" & (k +
1)) = 4
ThisWorkbook.Sheets("Forecast").Range("F" & (k +
1)) = varCode
k = k + 1
End If
Next j
End If
Exit For
End If
....


--
Arvi Laanemets
( My real mail address: arvil<attarkon.ee )



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 510
Default Excel2000: code too slow

Hi

Your response did give me an idea to test the source workbook. I copied
cource data to new workbook, and imorted from there - it worked like charm.
But I'm really confused - the delay was in part of code after
Application.Statusbar... row, and there is only one statement reading a
value from source table. A plain value - not a formula! At same time in code
I posted I skipped several statements where other data from same source
table were read - and those statements worked without any delay.
PS. The source workbook contains a couple of pivot tables based on same
table as my source table. But I can't see how this can influence the reading
of data from their common source table!

But the case is closed now anyway - and I thank you!


--
Arvi Laanemets
( My real mail address: arvil<attarkon.ee )



"Toppers" wrote in message
...
Arvi,
I emulated your code by simply selecting 2000 records (to
generate 24000) and it took less than a minute! So maybe my emulation was
not
realistic but I cannot understand why it would hours (never mind 10
minutes).

Unless there is reason not to do so, you could format the columns prior to
insert the data rather than in the loop - this speeds things up.

I have Excel 2003 but I don't believe this makes any (significant)
difference over 2000.


If you have file you can send me with all the code, I would willing to
test
further.

)


"Arvi Laanemets" wrote:

Hi

The code snippet below works too slow. It exports data from one Excel
table
(Customer,CustCode, Article, January, ..., December) to new one in
different
workbook (CustCode, Article, FirstWorkdayOfMonth, EntryType, CustCode).
It
looks like the problem is writing data to new table - writing 12 months
data
(12*5 fields) from a row in source table into new table takes ~50 sec. As
the source table has almost 2000 rows, and most of rows have values for
all
12 months, it takes 10 hours to generate the new table. (The rest of
code
takes next to nothing to run - the code row displaying process info on
status bar was added to check this)

At start I used offset to determine target cells, and suspected this to
be
the cause. So I replaced offsets with direct references - but this had no
effect at all.

Can anyone explain me this? Thanks in advance!

....
k = 0
....
If
Workbooks(varSource).Sheets(varSheet).Range("A1"). Offset(i - 1, 1) =
varCode
Then
varArticle =
Workbooks(varSource).Sheets(varSheet).Range("A1"). Offset(i - 1, 2)
For j = 1 To 12
If
Workbooks(varSource).Sheets(varSheet).Range("A1"). Offset(i - 1, j + 2)
0
Then
Application.StatusBar = "Code: " & varCode &
",
Article: " & varArticle & ", Month:" & arrMonths(j)

ThisWorkbook.Sheets("Forecast").Range("A" &
(k +
1) & ":C" & (k + 1)).NumberFormat = "@"
ThisWorkbook.Sheets("Forecast").Range("D" &
(k +
1) & ":E" & (k + 1)).NumberFormat = "General"
ThisWorkbook.Sheets("Forecast").Range("F" &
(k +
1)).NumberFormat = "@"
ThisWorkbook.Sheets("Forecast").Range("A" &
(k +
1)) = varCode
ThisWorkbook.Sheets("Forecast").Range("B" &
(k +
1)) = varArticle
ThisWorkbook.Sheets("Forecast").Range("C" &
(k +
1)) = arrMonths(j)
ThisWorkbook.Sheets("Forecast").Range("D" &
(k +
1)) = Workbooks(varSource).Sheets(varSheet).Range("A1"). Offset(i - 1, j +
2)
ThisWorkbook.Sheets("Forecast").Range("E" &
(k +
1)) = 4
ThisWorkbook.Sheets("Forecast").Range("F" &
(k +
1)) = varCode
k = k + 1
End If
Next j
End If
Exit For
End If
....


--
Arvi Laanemets
( My real mail address: arvil<attarkon.ee )





Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Slow Code Shawn Excel Programming 7 August 23rd 05 08:44 PM
"Group" function very slow with Excel 2003 :( ... While very quick with Excel2000 :O) Alain79 Excel Discussion (Misc queries) 4 June 14th 05 07:34 AM
SLOW Code... Ernst Guckel[_4_] Excel Programming 2 March 20th 05 10:58 AM
Slow Code Frank Kabel Excel Programming 1 July 23rd 04 09:28 AM
Is this slow code? Tom Excel Programming 4 March 3rd 04 11:18 PM


All times are GMT +1. The time now is 12:43 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"