Mon, 14 Jul 2008

Keep things simple: Order of an excel file.

One of my co-workers was asked to colorize an excel file. The task is simple but fastidious: for each row that has the value of the column `status' equal to 0, the background should be in red. If the value is 1, it should be with a pink background. Other values should be left untouched. The spreadsheet file contained about 2000 rows, and the order of the rows should not be modified.

I first thought about a macro to perform the task, but if I show her how this tedious task could be done that way, she would come to me everytime she think a task could be achieved by using macro, and she's not geek enough to learn how to write macros. Two more thinkings and I come to a simpler solution.

The first thing to do is to add an additional column to the table. It is called rank and have the value 1, 2, ... and so on incremented by 1 to the number of rows. It's very simple with Microsoft Excel to create a column with values autoincremented by 1: simply by writing 1 on the first row, 2 on the second, selecting these 2 cells and enlarging the selection to the entire column by dragging down the bottom-right corner of the selection. This additional column will help us preserve the original ordering of rows. Next thing is to select the entire sheet, then order it by the column status. All rows with the value 0 or 1 for the column status are now grouped. They can be selected respectively only once by dragging the mouse on the line number column. After having applied the color attributes, I just have to reorder the entire sheet by the column rank I created to get the initial ordering of rows, and to finish, I have just to remove this column and voilà.

The most pleasant thing is that the co-worker understood perfectly all the manipulations I've showed her. And I understood that writing cool and smart macro codes is not always cool and smart; many times, I just need to keep my thoughts simple and stupid.

posté le: 11:43 | path: /data/misc | permalien
Mars 2010
Dim Lun Mar Mer Jeu Ven Sam
 
     

Malagasy miray
About

DotMG's joblog

Work hard at whatever you do. (Ecc. 9. 10a. CEV)
Valid XHTML 1.0 Transitional   Valid CSS!   Powered by blosxom 2.0