Using Excel to build a simple dashboard

Excel charts are great visual tools to show changes in data. You can build dynamic charts in Excel with a few easy steps. Below is an example of a table which can be used to build an interactive chart.

Basic data

The Quantity column’s values are simply entered into the cells, but the Revenue figures are the result of the formula =B2*C2, which is copied down the column. The Selling Price is generated by multiplying the Base Price (see below) with the Price Change showing in the drop-down list in H2 (also shown below, but more about the drop-down list later). The formula is: =F2+F2*$H$2. The $ symbols in the formula are used to lock the percentage in the formula when you copy it down, because it is only in the one cell.

Base & dropdown

Select cell H2. To create the drop-down list, you need to have a normal list entered into some cells beforehand, as shown below. The drop-down is created by clicking the Data tab, then clicking Data Validation. In the box, select List from the Allow drop-down. Next, click inside the Source field, then select the list of figures in the cells (J2:J8 in this example). Now you have a drop-down list in cell H2.

Drop-down

As shown earlier, the figure shown in the drop-down cell (H2) is linked into the formula calculating the Selling Price. You can now change the Selling Price using the drop-down. And because the Selling Price is linked to the Revenue by a formula, these numbers also change!

The final step is inserting a chart which shows the Regions and their Revenues. To do this, first select the regions (including the label). Then hold down the Ctrl button and also select the revenue figures, again including the label.

Select columns

Now click the Insert tab, then click the Clustered Column option. This will insert a clustered column chart into your spreadsheet.

Charts

Move the chart to a suitable spot in your sheet, then test the drop-down list. See the magic happen as the chart changes when you select different values in the drop-down list!

Final

Excel course is one of our Microsoft Office 365 training courses.

SpecialCells in VBA

How to use SpecialCells method in Excel VBA

SpecialCells in VBA is a really useful method to deploy in Excel. It returns a Range Object that only covers the type of cells you specify. You can use the SpecialCells in VBA Method to return a Range Object that only holds numbers, text, blank cells, formulae, cells with datavalidation, cells with conditional formatting, the last cell in the worksheet, cells with comments and all visible cells.

If you for example want to change formatting for all numbers in a worksheet you do not need more than one line in the Visual Basic Editor to do it.

Cells.SpecialCells(xlCellTypeConstants, xlNumbers).Style = “currency”

This line will change all numbers in the active worksheet to currency format.  The Range object Cells is used to tell Excel that you want to look at all the cells and the special cells method to decrease it to in this example only constants (xlCellTypeConstants) and again to decrease it to only numbers the criteria  xlNumbers is added to the SpecialCells Method.

Similar we can use the SpecialCells Method to return a Range Object that only holds text.

Cells.SpecialCells(xlCellTypeConstants, xlTextValues).Font.ColorIndex=3

This VBA line will change the font colour to red for all text in the active worksheet.

The SpecialCells Method syntax is;
expression.SpecialCells(Type, Value)

The Expression have to be a Range object such as Cells, Range(“A1:B200”), ActiveSheet.UsedRange etc.

The different types of special cells are:

  1. xlCellTypeAllFormatConditions (all formatted cells)
  2. xlCellTypeAllValidation (all cells with datavalidation)
  3. xlCellTypeBlanks (all blank cells)
  4. xlCellTypeComments (all cells with notes)
  5. xlCellTypeConstants (all cells containing constants (numbers or text))
  6. xlCellTypeFormulas (all cells with formulas)
  7. xlCellTypeLastCell (The last cell in all used ranges)
  8. xlCellTypeSameFormatConditions (all cells with the same formatting also conditional formatting)
  9. xlCellTypeSameValidation (all  cells with the same datavalidation)
  10. xlCellTypeVisible (alll visible cells)

You can also use a combination of the above options.

Cells.SpecialCells(xlCellTypeConstants, xlNumbers).SpecialCells(xlCellTypeAllValidation).Font.Color = vbRed

This line of VBA code will add red font colour to all cells with numbers & Datavalidation.

The SpecialCells in VBA Method is also very powerful if you want to test your data in an If Then Else decision code.

Capture
SpecialCells in VBA

 

In the example above all numbers are tested in the active worksheet if the value is greater than 7500. If the test is true 10% is added. The For Each loop is only running through cells with numbers.

The SpecialCells in VBA Method can be very handy if you need to remove blank rows from you Excel lists or Excel databases.

Capture

and after running the macro

Capture2

In the above example The SpecialCells Method finds all blank cells in the range from A3 to A27 and deletes the entire row.

You have a lot of variations you can use and you will find out that when you start using The SpecialCells method  you will save a lot of lines in your macros!