Sunday, July 19, 2009

Create In-Cell Column Chart


Sample Percentage Data with Bar

Mala Singh from our Graphics division came up with this interesting solution to produce the desired effect. Mala built a worksheet where each row is actually comprised of 2 merged rows. Cells B2 & B3 are merged together in a single cell. When the value in B2 is changed, a bit of VBA code in the worksheet pane will automatically adjust the height of row 2 & row 3. Cell C3 is colored blue and cell C2 is colored white. The effect is that column C appears to show a column chart in the cell. This image shows various heights of the blue bar in cells C2 through C13.

Merging Cells

The first step is to merge cells B2 & B3 into a single cell. You will select cells B2 & B3. From the menu, select Format, Cells. Go to the Alignment tab. Check the box for Merge cells. This will cause B2 & B3 to act as a single cell called B2.

Leave cell C2 with no fill and use any color fill for cell C3.

Code for this technique is not placed in a regular module. It is "event handler" code and must be placed on the code module for this particular worksheet. Read Event Macro to Add Path and Filename to Excel Header article for a visual of how to open the code module for a worksheet.


No comments:

Post a Comment