Thanks for your reply.
To let you understand, I've included a snippet of the code which I have to
run to produce the results I need:
Sub test()
'
' Copy Columns from "Master" sheet to "Optimizer" sheet
'
Sheets("Master").Select
Selection.CurrentRegion.Copy
Sheets("Optimizer").Range("M1").PasteSpecial Paste:=xlValues,
Operation:=xlNone, SkipBlanks:= _
False, Transpose:=False
Application.CutCopyMode = False
'
' Copy Cutting List to Optimizer Columns (A & B), then Optimize
'
Sheets("Optimizer").Select
'1 (Run the first Iteration)
Columns("M:N").Copy
Range("A1").PasteSpecial Paste:=xlPasteValues, Operation:=xlNone,
SkipBlanks _
:=False, Transpose:=False
Call optimizer ' This calls up the bin-packing algorithm
Range("D3").Copy 'This is where the results from the bin-packing
algorithm appear after each iteration.
Range("F2").PasteSpecial Paste:=xlPasteValues, Operation:=xlNone,
SkipBlanks _
:=False, Transpose:=False 'This is where the result from above is
saved
'2 (Run the second Iteration)
Columns("O
").Copy
Range("A1").PasteSpecial Paste:=xlPasteValues, Operation:=xlNone,
SkipBlanks _
:=False, Transpose:=False
Call optimizer
Range("D3").Copy
Range("F3").PasteSpecial Paste:=xlPasteValues, Operation:=xlNone,
SkipBlanks _
:=False, Transpose:=False
'3
Columns("Q:R").Copy
Range("A1").PasteSpecial Paste:=xlPasteValues, Operation:=xlNone,
SkipBlanks _
:=False, Transpose:=False
Call optimizer
Range("D3").Copy
Range("F4").PasteSpecial Paste:=xlPasteValues, Operation:=xlNone,
SkipBlanks _
:=False, Transpose:=False
'4
Columns("S:T").Copy
Range("A1").PasteSpecial Paste:=xlPasteValues, Operation:=xlNone,
SkipBlanks _
:=False, Transpose:=False
Call optimizer
Range("D3").Copy
Range("F5").PasteSpecial Paste:=xlPasteValues, Operation:=xlNone,
SkipBlanks _
:=False, Transpose:=False
'5
Columns("U:V").Copy
Range("A1").PasteSpecial Paste:=xlPasteValues, Operation:=xlNone,
SkipBlanks _
:=False, Transpose:=False
Call optimizer
Range("D3").Copy
Range("F6").PasteSpecial Paste:=xlPasteValues, Operation:=xlNone,
SkipBlanks _
:=False, Transpose:=False
' These iterations are repeated until all pairs of columns from M:N to
IU:IV have been utilised. (122 iterations)
End Sub
What I'm trying to achieve is to run a copy loop which will copy columns two
at a time (based on the number of columns with data in them, starting at
columns M & N), copy these columns to location (columns A & B), run the
optimizer macro, then copy the result sequentially to cells F2, F3, F4, F5
etc..
I have just included the first 5 or so iterations, but to let you know, the
number of columns that are copied into the spreadsheet varies (new cutting
lists for different jobs etc.). i.e I may need to copy just four columns (in
2 pairs, one after the other), or I may have to copy 50 columns etc.. The
column headings for each pair of columns is always:
No. of Pieces Cut Length (mm).
In short, I'm just trying to create a loop to do the above, based on the
number of columns with data in them, rather than do it a fixed number of
times (122 iterations, which slows the process down).
I hope this is enough info, if you need more details, please get back in
touch.
Thanks again