ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   dec2bin (https://www.excelbanter.com/excel-programming/316194-dec2bin.html)

Jo[_6_]

dec2bin
 
Hi
Is there something analagous to dec2bin (worksheet) for
VBA?
I need to change a 5 digit decimal into a 16 character
binary expression.
Thanks
Jo

keepITcool

dec2bin
 

this should do..

Function DecToBin(ByVal Number As Long, _
Optional Places As Integer) As String
Dim l As Long, s As String

l = Number
Do
s = (l Mod 2) & s
l = l \ 2
Loop While l 0
If Places 0 And Places Len(s) Then
s = String$(Places - Len(s), "0") & s
End If

DecToBin = s

End Function





--
keepITcool
| www.XLsupport.com | keepITcool chello nl | amsterdam


Jo wrote :

Hi
Is there something analagous to dec2bin (worksheet) for
VBA?
I need to change a 5 digit decimal into a 16 character
binary expression.
Thanks
Jo



All times are GMT +1. The time now is 10:48 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
ExcelBanter.com