maurice

Here’s all the places that I’ve visited in my life.
Are considered ‘visited’ somewhere where I slept at least one night.

There’s still a hell of a lot of places to go

The upcoming presidential election in the USA brings some interesting candidates on the republican front. We have:

  • Mitt Romney, who believes in a church founded by one Joseph Smith, who was directed to a buried book written on golden plates, containing the religious history of an ancient people. Conveniently, the angel took the plates back once Smith had translated them, but in a nutshell, american indians are in fact descendants of jews who emigrated to America. Even those with a faint knowledge of the bible will recognise the plagiarism.
  • Ron Paul, raised a lutheran but now a church-going baptist, appears to be saner, but nonetheless endorses using the 1st amendment to ensure that religious speech is above the law (as long as it’s lutheran/baptist, of course).
  • Newt Gringrich, also raised as a lutheran but now a catholic, tellingly said in a 2011 appearance in Columbus, Ohio: “In America, religious belief is being challenged by a cultural elite trying to create a secularized America, in which God is driven out of public life.”

What, I ask myself, is the difference between these fruit-cakes and muslim extremists? Or have they all forgotten the treaty of Tripoli?

I’ve wasted hours trying to figure out why my embedded geocoding application doesn’t work with IE9.

This is not the first bad experience I’ve had with IE9, which frankly is one of the worst browser implementations I’ve ever seen.

If you’ve arrived here, you’re probably looking for a solution. Here’s what worked for me:

<meta http-equiv="X-UA-Compatible" content="IE=EmulateIE7" >

That we have to resort to this kind of shit beggars belief.

This spreadsheet contains the VBA code to write an Excel range as a clean, formatted HTML page, with optional auto-refresh.

Features:

  • Correctly renders all Excel formatting, including conditional formats.
  • Renders embedded charts.
  • Generates an HTML page with tabs identical to those in the Excel file.
  • Creates clean, formatted HTML that validates to HTML 4.01 strict.
  • Optimised stylesheet to ensure minimal page weight.
  • Supports merged cells with ROWSPAN and COLSPAN.
  • Updates the webpage automatically when cells’ values are changed.
  • The webpage automatically refreshes itself at a user-supplied interval.

The result is almost pixel-perfect, compare this Excel screenshot with the HTML page it generated.

I though this would be trivial; turns out it’s not.

  • When you copy a formula from the clipboard, relative references are adjusted, so Range(x).Formula=Range(y).Formula doesn’t produce the expected results. The correct way is Range(x).Formula=Range(y).FormulaR1C1. Easy once you’ve been there.
  • Copying border formats with Range(x).Borders=Range(y).Borders crashes Excel. You have to copy each individual border, left, right, top, etc.
  • Similarly for fonts, you have to copy the font attributes one by one.
  • Good practice: check that the areas have compatible sizes and don’t overlap.

Nothing inordinately difficult, but time-consuming to get right. Here’s the code:

Option Explicit

' Copy cells without using the clipboard.
'
' Source is a range from which to copy values/formulas/formats.
' Dest is the destination range. Must be either
'     a single cell, the top-left of the target range. The source size (rows x columns) is copied.
'   or
'     a range exactly the same size as source. We throw an error if the shapes don't match.
'
' If 'what' is omitted, copies the values.
' what=CopyFormulas copies the formulas instead of the values.
' what=CopyFormats copies the formats.
' what=CopyFormulas+CopyFormats copies both.
'
' Examples:
'   CopyCells Range("b2:c6"), Range("h10")                                   ' Copies 8 cells (6x2) from B2 to H10
'   CopyCells Range(cells(2,2),cells(6,3)), Range("h10")                     ' Idem
'   CopyCells Range(cells(2,2),cells(6,3)), Range(cells(10,10),cells(14,12)) ' Fails, source is 6x2, dest is 6x3
'   CopyCells Range("b2:c6"), Range("b3")                                    ' Fails, source and dest intersect

Public Const CopyFormulas = 1
Public Const CopyFormats = 2
Public Sub CopyCells(source As Range, dest As Range, Optional what As Long)

    ' Turn off screen updating, wastes (a lot of) time
    Dim updating As Boolean
    updating = Application.ScreenUpdating
    Application.ScreenUpdating = False

    If IsMissing(what) Then
        what = 0
    End If

    Dim r As Long
    Dim c As Long

    ' If destination is not a singe (r,c) top-left cell, ensure that the ranges are the same shape and size
    If dest.Rows.Count > 1 Or dest.Columns.Count > 1 Then

        If dest.Rows.Count <> source.Rows.Count Or _
           dest.Columns.Count <> source.Columns.Count Then

            Err.Raise 1000, "CopyCells", "Destination area " & dest.Rows.Count & "x" & dest.Columns.Count & _
                " is not the same shape as the source area " & source.Rows.Count & "x" & source.Columns.Count

        End If
    End If

    If Not (Intersect(source, dest) Is Nothing) Then
            Err.Raise 1000, "CopyCells", "Source area " & Replace(source.Address, "$", "") & " " & source.Rows.Count & "x" & source.Columns.Count & _
                " intersects destination area " & Replace(dest.Address, "$", "") & " " & dest.Rows.Count & "x" & dest.Columns.Count
    End If

    For r = 1 To source.Rows.Count

        For c = 1 To source.Columns.Count

            If what And CopyFormulas Then
                dest.Cells(r, c).Formula = source.Cells(r, c).FormulaR1C1
            Else
                dest.Cells(r, c).Value = source.Cells(r, c).Value
            End If

            If what And CopyFormats Then

                Dim b As Long
                For b = xlEdgeLeft To xlInsideHorizontal
                    With source.Cells(r, c).Borders(b)
                        dest.Cells(r, c).Borders(b).Weight = .Weight ' You must do this *before* linestyle
                        dest.Cells(r, c).Borders(b).LineStyle = .LineStyle
                        dest.Cells(r, c).Borders(b).ColorIndex = .ColorIndex
                        dest.Cells(r, c).Borders(b).TintAndShade = .TintAndShade
                    End With
                Next
                dest.Cells(r, c).ColumnWidth = source.Cells(r, c).ColumnWidth
                dest.Cells(r, c).Interior.Color = source.Cells(r, c).Interior.Color
                dest.Cells(r, c).Interior.Pattern = source.Cells(r, c).Interior.Pattern
                dest.Cells(r, c).HorizontalAlignment = source.Cells(r, c).HorizontalAlignment
                dest.Cells(r, c).IndentLevel = source.Cells(r, c).IndentLevel
                dest.Cells(r, c).NumberFormat = source.Cells(r, c).NumberFormat
                dest.Cells(r, c).Orientation = source.Cells(r, c).Orientation
                dest.Cells(r, c).RowHeight = source.Cells(r, c).RowHeight
                dest.Cells(r, c).UseStandardHeight = source.Cells(r, c).UseStandardHeight
                dest.Cells(r, c).UseStandardWidth = source.Cells(r, c).UseStandardWidth
                dest.Cells(r, c).VerticalAlignment = source.Cells(r, c).VerticalAlignment
                dest.Cells(r, c).WrapText = source.Cells(r, c).WrapText

                With source.Cells(r, c).Font
                    dest.Cells(r, c).Font.Background = .Background
                    dest.Cells(r, c).Font.Bold = .Bold
                    dest.Cells(r, c).Font.Color = .Color
                    dest.Cells(r, c).Font.ColorIndex = .ColorIndex
                    dest.Cells(r, c).Font.FontStyle = .FontStyle
                    dest.Cells(r, c).Font.Italic = .Italic
                    dest.Cells(r, c).Font.Shadow = .Shadow
                    dest.Cells(r, c).Font.Size = .Size
                    dest.Cells(r, c).Font.Strikethrough = .Strikethrough
                    dest.Cells(r, c).Font.Subscript = .Subscript
                    dest.Cells(r, c).Font.Superscript = .Superscript
                    dest.Cells(r, c).Font.Underline = .Underline
                End With
                On Error GoTo 0
            End If

        Next
    Next

    Application.ScreenUpdating = updating

End Sub

Sub test()
    CopyCells Range("b2:c6"), Range("h10"), CopyFormulas + CopyFormats
End Sub

 

Whilst making fun of religions is commonplace, it’s extremely rare for religions to use humour themselves.

The United Methodist Church in Salem, Massachusetts certainly is an exception, which had me in stitches:

Just before Christmas 2010 I gave my yearly prediction as to how I saw the forex market evolving.
Those that read it heaped ridicule on me: “the dollar couldn’t devalue, it’s unthinkable, it’s the world’s reserve currency, you’re crazy”, “the Euro could never fall like that”.

Six months down the road, let’s take a look at how things really turned out.
The red line (USD) and pink line (EUR) are those I drew last Christmas, the green ones are the current situation on the 22nd of June 2011 (1 CHF=0.8360 USD = 1.2030 EUR):

The figures speak for themselves.

The media are once again obsessing about the economy, or more accurately the lack thereof, to a back-drop of procrastinating politicians who are no more qualified to administer public finances than chimps are to perform brain surgery.

Everyone seems to accept that a country’s economy shall be measured by the ratio of its public debt to its GDP. I question this, on the grounds that whilst America’s 8.5 trillion dollars is a lot of debt, it represents about 27’000 per inhabitant, which doesn’t really sound that bad. The Icelandic 15 billion dollar debt pales in comparison, but per inhabitant it’s 47’000, which is nearly double that if the USA.

Here’s the Public Debt versus GDP for a cherry-picked set of countries, essentially the developed and significant nations:

The numbers are in USD, source CIA Factbook, IMF and World Bank, in this spreadsheet PublicFinances.xls. The horizontal scale shows productivity, the vertical scale measures indebtedness. The grey triangle encompasses those countries whose public debt is less than a year’s GDP.

There are three coloured clusters, which group those who have similar economic habits.

  1. The Spendthrifts, with debt exceeding GDP. Japan has been trying to kick-start its economy for over a decade, it clearly hasn’t worked. That Iceland, Ireland and Greece are heavily in debt is hardly a surprise, but I didn’t expect Belgium and Singapore to be here.
  2. The Western Norm, with debt between 50% and 100% of GDP. Essentially the rest of Europe and the USA. Israel’s economic habits, predictably, are the same.
  3. The Cautious, with debt less than 50% of GDP. Here we have the Nordic countries, the true bankers and unexpectedly, Canada and Australia.

The others make for a few interesting observations.

China and India, regularly upheld as models of economic development, are still in abject poverty at the individual’s level. When average inhabitant generates 4$/day (India) or even 19$/day (China), even a homoeopathic increase in employment will give you 10% growth a year; certainly not a notable achievement. To put that into perspective, if China’s GDP increases by 10% (compounded) every year, it’ll reach Germany’s current productivity in 2035. I’m not holding my breath.

Despite their immense income from oil, the average Saudi’s income is barely a third that of an Irishman (but the Irishman has twenty times the debt).

Finally, for all the current fretting over the American debt, it’s comparatively modest in relation to the population. The Greek and Irish economies are getting lots of publicity, but there are others whose public finances are much worse. Italy, Belgium, Iceland and above all Japan are going to have a much rougher time putting their houses in order.

The Democrats and Republicans are slogging it out, trying to find a way to reduce the US debt. A laudable effort, but frankly, it’s pissing in the ocean. To see the big picture, we’ll take a look how the US government has been running its shop over the last century or so. Take the first half of that period, up until 1970, when the gold standard was abandoned. Notice that all numbers are in millions of dollars:

The second World War made a nasty dent in the finances, but that’s perfectly understandable. I’ve shaded the years where the books showed a ‘profit’ in green; there are precious few and the amounts are insignificant.

Since 1970, the picture changes drastically, we have to multiply the scale by a factor of 50’000; we’ve moved from millions to billions:

You might notice, correctly, that the debt in 2011 is shown around 9.6 trillion, when it is in fact 14.3 trillion. Presumably there’s another 5 trillion that was borrowed somewhere; a trifle that we’ll ignore.

The message to take away here is that the US government has balanced its books in 4 years out of the last 40. Perhaps more telling is that those 4 rare years are thanks solely to the dotcom bubble and the true value is directly correlated to the main thing it generated: hype.

The average American thus owes some 47’000$ on behalf of his government (and an average of 7’000$ on his credit card, but that’s another story).

Put in household terms, this is like earning 100’000 a year, spending 176’000 and borrowing a further 19’742 to pay the interest on the 657’864 that you borrowed in previous years.

Let’s zoom in on how the White House sees that debt evolving:

The dotcom money is put into perspective and we get to the part where I’m asking myself who’s been smoking something dubious. Remember, these are the numbers I obtained from the White House, which predicts that the debt will be reduced by 1’000’000’000’000$ in the next 4 years.

Thus, every American man, woman and child is going to reduce spending by 833$ every year, not to eliminate the debt, but simply to halve the yearly budget deficit.

The Americans are definitely in the shit; but the shit they’re in isn’t the shit that they’ve been smoking.

© 2012 Maurice's Musings