The following will go through every worksheet of every workbook in the current project (it might not be the most efficient code but seems to work okay based on a quick test):
dataset dsXCol = {}; // Dataset to hold X column data for new workbook- assigned at end of script
dataset dsYCol = {}; // Dataset to hold Y column data for new workbook
string strName$; // String to hold name of new book
newbook result:= strName$; // Create new workbook putting it's name into strName$
int jj = 1; // Counter for adding rows to above datasets
// Loop over every worksheet in project
doc -e LB {
if (exist(%H, 2) == 0) // Not a workbook, must be a matrix
{
continue;
}
if (%H == strName$) // Skip newly created workbook
{
continue;
}
range rngX = col(1); // The current worksheet X column
// Loop over all Y columns
for(int ii = 2 ; ii <= wks.ncols; ii++)
{
range rngY = col($(ii)); // The current worksheet Y column
limit rngY; // Puts some stats into tree LIMIT
dsXCol[jj] = rngX[limit.imax]; // Get X of row with maximum. Put into dsXCol dataset using jj counter
dsYCol[jj] = rngY[limit.imax]; // Get Y of row with maximum. Put into dsYCol dataset
jj++; // Increment jj counter for adding rows to above datasets
}
}
range rngCol1 = [%(strName$)]Sheet1!col(1); // Get column 1 of newly created workbook, sheet 1
range rngCol2 = [%(strName$)]Sheet1!col(2); // Get column 2 of newly created workbook, sheet 1
rngCol1 = dsXCol; // Assign X dataset to column 1
rngCol2 = dsYCol; // Assign Y dataset to column 2