2012-01-23

Death to Apostrophes (remove leading apostrophes from active excel sheet)

For those who has had the pleasure of working with accounting software which doesn't correctly create exports to excel, here is a tip to get rid of the irritating leading apostrophe in the cells which forces them to text.
Yes Pastel Accounting, I am looking at you!

It is a small macro which removes ALL the leading apostrophes from the current active sheet.

Sub DeathToApostrophe()
   'Removes the apostrophe at the start of each cell which forces the content to be text
   Dim s As Range
   For Each s In ActiveSheet.UsedRange
      If s.HasFormula = False Then
      s.Value = Trim(s.Text)
   End If
   Next s
End Sub

Note: This was copied and edited from the macro created by this guy (Zack Barresse). If you are unsure as to how to use the above macro, follow the previous link for more information.

Note regarding dates:
Take care with regards to dates which excel automatically recognises and converts to a DATE formate. Sometimes excel converts it to the incorrect date format, creating extra work for you if you notice it, or leads to error if you don't.

For example: I exported journals from Pastel accounting, and the date format for the specific company file was set to dd/mm/yyyy. I ran the DeathToApostrophe macro and excel recognised and converted the dates to a mm/dd/yyyy format where possible. I attempted in vain to adjust my regional settings in Windows and Excel to correct this behavior, but nothing worked.

The solution was to change the date format used by Pastel accounting to my regional settings (yyyy/mm/dd). In Pastel accounting the date format is company specific and can be changed through the following menu items: Setup > Company parameters > Formats (tab) > Date Entry Format (section).

I might be necessary to similarly change the way the source formats its dates to prevent errors when removing the apostrophes in excel.

1 comment:

  1. Here is a slightly more focussed one from http://support.microsoft.com/kb/124935 - it only does the cells that are highlighted. Why people still use Pastel as a first choice accounting system just boggles the mind:

    'Removes hidden apostrophes that are first characters.
    'Works on cells with formulas, text, or values.

    Sub ApostroRemove()
    For Each currentcell In Selection
    If currentcell.HasFormula = False Then
    'Verifies that procedure does not change the
    'cell with the active formula so that it contains
    'only the value.
    currentcell.Formula = currentcell.value
    End If
    Next
    End Sub

    ReplyDelete