Hi Tek-Tippers.
I could really use your help here. I have tried several different things trying to speed up the code below, but it still takes an unusually long time.
I've got Application.Events & .Screenupdating set to false.
I also have Application.Calculation set to manual.
Below is the loop which runs through a 2 dimensional table defined by 2 named ranges, "Products" and "Entities". All I'm doing is plotting the 2 dimensional data into a single dimension worksheet. I 1st had the commented code below, but found (to my amazement!) that the copy / paste was faster! (but still slow overall).
ANY HELP WOULD BE GREATLY APPRECIATED!
innov
-------------------------------------------------------
Sub Rules_Export()
Application.EnableCancelKey = xlDisabled
error_source = "Export Rules"
If trap_errors Then: On Error GoTo Err_Handler
If Not Valid_Output_Folder Then: Exit Sub
ScrUpd (False)
Events (False)
AutoCalc (False)
Dim exppath, expfile, exptype, fileext, DriveSep As String
exppath = IIf(Right(FilePath, 1) = "\", FilePath, FilePath + "\")
' expfile = [RulesExport_File] 'need to capture since we're leaving this wkbk below
' exptype = [RulesExport_Type]
exptype = "XLS"
exp_row = 1 'set to 1. loop will skip first (header) row
prod_cnt = 0
ent_cnt = 0
'---- column numbers ----
date_col = 1
time_col = 2
prod_num_col = 3
prod_code_col = 4
prod_desc_col = 5
prod_src_col = 6
prod_lnamt_col = 7
prod_cap_col = 8
prod_adj1_col = 9
prod_adj2_col = 10
ent_name_col = 11
ent_mrg_col = 12
ent_lnamt_col = 13
ent_cap_col = 14
expdate = Format(Date$, "yyyy/mm/dd")
expfdate = Format(Date$, "yyyymmdd")
exptime = Format(Time$, "hh:mm:ss")
RulesExport.Unprotect (wksh_pswd)
RulesExport.Range("A2:Z12000").ClearContents
frm_Export.Show
frm_Export.Repaint
'-- Traverse the Rules table: (a) by Product; (b) by Entity
For Each prod In [Products]
If Len(Trim(prod.Value)) > 0 Then
prod_cnt = prod_cnt + 1
For Each ent In [Entity_Area]
If Not Len(Trim(ent.Value)) > 0 Then
Exit For
End If
ent_col = _
WorksheetFunction.Match(ent, [Entities], 0) + _
Entities].Column - 1
exp_row = exp_row + 1
RulesExport.Cells(exp_row, date_col) = expdate
RulesExport.Cells(exp_row, time_col) = exptime
'--- product level info ---------
'RulesExport.Cells(exp_row, prod_num_col) = Rules.Cells(prod.Row, prod.Column - 1)
'RulesExport.Cells(exp_row, prod_code_col) = Rules.Cells(prod.Row, prod.Column)
'RulesExport.Cells(exp_row, prod_desc_col) = Rules.Cells(prod.Row, prod.Column + 1)
'RulesExport.Cells(exp_row, prod_adj1_col) = Rules.Cells(prod.Row, prod.Column + 5)
'RulesExport.Cells(exp_row, prod_adj2_col) = Rules.Cells(prod.Row, prod.Column + 6)
'RulesExport.Cells(exp_row, prod_lnamt_col) = Rules.Cells(prod.Row, prod.Column + 3)
'RulesExport.Cells(exp_row, prod_cap_col) = Rules.Cells(prod.Row, prod.Column + 4)
'--- entity level info ----------
'RulesExport.Cells(exp_row, ent_name_col) = ent.Value
'RulesExport.Cells(exp_row, ent_mrg_col) = Rules.Cells(prod.Row, ent_col)
'RulesExport.Cells(exp_row, ent_lnamt_col) = Rules.Cells(prod.Row, ent_col + 1)
'RulesExport.Cells(exp_row, ent_cap_col) = Rules.Cells(prod.Row, ent_col + 2)
'--- product level info ---------
Rules.Range(Cells(prod.Row, prod.Column - 1), Cells(prod.Row, prod.Column + 6)).Copy
RulesExport.Cells(exp_row, prod_num_col).PasteSpecial (xlValues)
'--- entity level info ----------
ent.Copy
RulesExport.Cells(exp_row, ent_name_col).PasteSpecial (xlValues)
Rules.Range(Cells(prod.Row, ent_col), Cells(prod.Row, ent_col + 1)).Copy
RulesExport.Cells(exp_row, ent_mrg_col).PasteSpecial (xlValues)
Application.CutCopyMode = False
Next ent
End If
Next prod
*- code to save temp workbork "as xyz" ---
Events (True)
AutoCalc (True)
ScrUpd (True)
End Sub
I could really use your help here. I have tried several different things trying to speed up the code below, but it still takes an unusually long time.
I've got Application.Events & .Screenupdating set to false.
I also have Application.Calculation set to manual.
Below is the loop which runs through a 2 dimensional table defined by 2 named ranges, "Products" and "Entities". All I'm doing is plotting the 2 dimensional data into a single dimension worksheet. I 1st had the commented code below, but found (to my amazement!) that the copy / paste was faster! (but still slow overall).
ANY HELP WOULD BE GREATLY APPRECIATED!
innov
-------------------------------------------------------
Sub Rules_Export()
Application.EnableCancelKey = xlDisabled
error_source = "Export Rules"
If trap_errors Then: On Error GoTo Err_Handler
If Not Valid_Output_Folder Then: Exit Sub
ScrUpd (False)
Events (False)
AutoCalc (False)
Dim exppath, expfile, exptype, fileext, DriveSep As String
exppath = IIf(Right(FilePath, 1) = "\", FilePath, FilePath + "\")
' expfile = [RulesExport_File] 'need to capture since we're leaving this wkbk below
' exptype = [RulesExport_Type]
exptype = "XLS"
exp_row = 1 'set to 1. loop will skip first (header) row
prod_cnt = 0
ent_cnt = 0
'---- column numbers ----
date_col = 1
time_col = 2
prod_num_col = 3
prod_code_col = 4
prod_desc_col = 5
prod_src_col = 6
prod_lnamt_col = 7
prod_cap_col = 8
prod_adj1_col = 9
prod_adj2_col = 10
ent_name_col = 11
ent_mrg_col = 12
ent_lnamt_col = 13
ent_cap_col = 14
expdate = Format(Date$, "yyyy/mm/dd")
expfdate = Format(Date$, "yyyymmdd")
exptime = Format(Time$, "hh:mm:ss")
RulesExport.Unprotect (wksh_pswd)
RulesExport.Range("A2:Z12000").ClearContents
frm_Export.Show
frm_Export.Repaint
'-- Traverse the Rules table: (a) by Product; (b) by Entity
For Each prod In [Products]
If Len(Trim(prod.Value)) > 0 Then
prod_cnt = prod_cnt + 1
For Each ent In [Entity_Area]
If Not Len(Trim(ent.Value)) > 0 Then
Exit For
End If
ent_col = _
WorksheetFunction.Match(ent, [Entities], 0) + _
Entities].Column - 1
exp_row = exp_row + 1
RulesExport.Cells(exp_row, date_col) = expdate
RulesExport.Cells(exp_row, time_col) = exptime
'--- product level info ---------
'RulesExport.Cells(exp_row, prod_num_col) = Rules.Cells(prod.Row, prod.Column - 1)
'RulesExport.Cells(exp_row, prod_code_col) = Rules.Cells(prod.Row, prod.Column)
'RulesExport.Cells(exp_row, prod_desc_col) = Rules.Cells(prod.Row, prod.Column + 1)
'RulesExport.Cells(exp_row, prod_adj1_col) = Rules.Cells(prod.Row, prod.Column + 5)
'RulesExport.Cells(exp_row, prod_adj2_col) = Rules.Cells(prod.Row, prod.Column + 6)
'RulesExport.Cells(exp_row, prod_lnamt_col) = Rules.Cells(prod.Row, prod.Column + 3)
'RulesExport.Cells(exp_row, prod_cap_col) = Rules.Cells(prod.Row, prod.Column + 4)
'--- entity level info ----------
'RulesExport.Cells(exp_row, ent_name_col) = ent.Value
'RulesExport.Cells(exp_row, ent_mrg_col) = Rules.Cells(prod.Row, ent_col)
'RulesExport.Cells(exp_row, ent_lnamt_col) = Rules.Cells(prod.Row, ent_col + 1)
'RulesExport.Cells(exp_row, ent_cap_col) = Rules.Cells(prod.Row, ent_col + 2)
'--- product level info ---------
Rules.Range(Cells(prod.Row, prod.Column - 1), Cells(prod.Row, prod.Column + 6)).Copy
RulesExport.Cells(exp_row, prod_num_col).PasteSpecial (xlValues)
'--- entity level info ----------
ent.Copy
RulesExport.Cells(exp_row, ent_name_col).PasteSpecial (xlValues)
Rules.Range(Cells(prod.Row, ent_col), Cells(prod.Row, ent_col + 1)).Copy
RulesExport.Cells(exp_row, ent_mrg_col).PasteSpecial (xlValues)
Application.CutCopyMode = False
Next ent
End If
Next prod
*- code to save temp workbork "as xyz" ---
Events (True)
AutoCalc (True)
ScrUpd (True)
End Sub