Thursday, October 28, 2010

En, Em, Eh, What?

There are different types of dashes: hyphen, en dash, and em dash. What is the difference between them?

Hyphen (-): This is the width of one digit. It is used to hyphenate words that break across a new line, or to join compound words. Ex. My, this professor is long-winded.

En Dash (–): This is the width of the letter 'n'. It is used to indicate a range of values. Ex. I will be on vacation from November 6–10.

Em Dash (—): This is the width of the letter 'w'. This is used to indicate a break in thought. Ex. I was eating pizza—and what a good pizza it was—with all my favorite toppings.

Using courier font we can get a better idea of the widths:
0 n m
- – —
[Sources: Fonts.com and Wikipedia]

Tuesday, October 12, 2010

Excel Macro for Background Color


I was writing an Excel Macro and I needed to set the background color of a cell based on the text value. To do this I wanted to use Conditional Formatting, and I found out that you cannot (AFAIK) setup Conditional Formatting from inside of a macro. But, you can create a macro that loops through a range and sets the formatting.

Here is how:
  1. Open the VB editor (Alt + F11)
  2. Open ThisWorkbook under Microsoft Excel Objects
  3. Add the following code:
Private Sub Workbook_SheetChange(ByVal Sh As Object, ByVal Target As Range)
Set myRange = Range("C4:C104")
    For Each Cell In myRange
        If Cell.Value = "n" Then
            Cell.Interior.ColorIndex = 3
        End If
    Next
End Sub

Anytime  a change is made to the workbook, the macro is called. It checks a range of cells, and then if the text is 'n' it sets the background color to 3. But what is '3'?