convert binary to decimal

K

Krishnakanth

i have given the folloing command in one of the cell.

=BIN2DEC(1100100)

When I hit enter i am getting the following text.

#NAME?

Can anyone help me fix this problem.

Krishnakanth M
 
J

Joel

Here is a UDF that you can use.

Function BIN2DEC(data As Variant) As Variant

If Not IsNumeric(data) Then
data = Format(data, "text")
Else
data = Trim(data)
End If
BIN2DEC = 0
Do While data <> ""
NewChar = Left(data, 1)
data = Mid(data, 2)
Select Case NewChar
Case "0"
BIN2DEC = 2 * BIN2DEC
Case "1"
BIN2DEC = (2 * BIN2DEC) + 1
Case Else
BIN2DEC = "Not Binary"
End Select
Loop

End Function
 
Top