

Copy the code in and run the 'tester' sub.Text is a worksheet function in excel but it can also be used in VBA while using the range property with it, the function for this function is similar to the worksheet function and it takes the same number of arguments which are the values which needs to be converted and a specified number format.

The second argument to the function is the base of the number representation provided in the first argument. The function can then be called by other procedures within that workbook or used directly in the worksheets of the workbook. Copy the code to a standard module in a workbook.LVal = lVal + (WorksheetFunction.Match(Mid$(BaseVal, i, 1), Digits, False) - 1) * (base ^ (Len(BaseVal) - i)) 'generate decimal values of BaseVal digits: Base needs to be specified as decimal ie '8 for base 8, 16 for base 16, 2 for base 2 etcĭim i As Long, sTemp As String, lVal As Long 'converts a string representation of a number in base(base) to the equivalent in decimal '(base 2 to base 16). Public Function Base2Dec(ByVal BaseVal As String, ByVal base As Long) As Variant 'testing sub - this code is NOT required to run the function - it only 'demonstrates the function in operation The outputted long decimal's maximum value is 2,147,483,647. This extends the functionality provided by the Analysis Toolpak functions such as BIN2DEC and HEX2DEC. The two together permit conversion from one base (base 2 to base 16) to any other base in this range. This is the complementary function to the Dec2Base function here: Provides a VBA function to convert a string representation of a number in the specified base (in the range base 2 to base 16) to its decimal equivalent.
