Conversion of excel function to vba code