Here is a little script that I think will do what you want. It orders the columns as you suggested, plus it groups each of the compounds into separate column groups.
Names default to here(1);
groupList = {"RES_VALUE","RES_TEXT", "DETECT_FLAG", "RL", "DILUTION_FACTOR" };
// The comment lines below, when uncommented will create a small example data table
// that was used to test the code
/*compList = {"4:2 FTS", "6:2 FTS", "ADONA" };
New Table("Example");
for each({group}, groupList,
for each({comp},compList,
New Column(group || " " || comp)
)
);*/
dt = current data table();
// Find all of the different compounds. This is done by using the "RES_VALUE" columns
// and stripping off the compound names from each of them
compList = {};
For( i=1,i<=N Cols(dt), i++,
colName = column(dt,i)<<get name;
if(contains( colName,"RES_VALUE")==1,
insert into(compList,substr(colName,11))
)
);
// Order each of the Compound columns together
For Each( {comp}, compList,
varList = {};
For Each( {group}, groupList,
insert into(varList, group || " " || comp)
);
dt << select columns( varList);
dt << Move Selected Columns( To last );
dt << group columns( comp, varList);
);
Jim