【VBA】Convert decimal to binary

You can convert decimal to binary!

Use the following Worksheet function:
 Dec2Bin Function

PR

VBA Code

You can convert decimal to binary.

Option Explicit

Sub sampleProc()
    
    Dim targetNum As Long
    
    'Set "target decimal"
    targetNum = 10

    'Convert decimal to binary
    MsgBox WorksheetFunction.Dec2Bin(targetNum, 6)
    
End Sub

Set “target decimal“(Line 8).

Convert decimal to binary(Line 11).
※1nd argument・・・Set “target decimal“.
※2nd argument・・・Set “number of digits”.

PR

Result

You converted decimal to binary!

Result
Result
PR

FYI No.1

Also, you can convert binary to decimal!

For more information, see the following article:

PR

FYI No.2

For more information about following, see the following official online manual:

Dec2Bin method” of “WorksheetFunction Object”


DEC2BIN Function

タイトルとURLをコピーしました