Excel- DNA C# Script – for adding a missing “0” in Danish Social Security Number

Since I wrote this UDF in VBA; I have had plans for making a version written purely in C#- simply to make a higher performing function for large volume data. Excel-DNA UDF makes faster calculations than Excel  – some estimates say 40% faster calculation rate  than excel VBA. I have to test that claim !
In my opinion Visual developer  is way superior to Excel’s programming interface in many respects.

 

Anyway here it comes:

 

[ExcelFunction(Description = “Adding missing “0” infront of danish CPR number”)]

public static object CorrectCPR(int CCR,object CCRU)

  {

String InterN;

InterN = Convert.ToString(CCR);

if (InterN.Length == 9)

 

  {

       CCRU = (“0”) + CCR;

   }

  else

  if (InterN.Length == 10)

  {

     CCRU = CCR;

  }

  else

  if (InterN.Length >= 11)

  {

     CCRU = 99;

  }

    return CCRU;

  }

  }

 

For further reading https://excel-dna.net/