数値を16進数に変換します。
最終行の取得は、最終行取得(空白まで) (GetBlankRow)を使用しています。
以下のコードは、変換関数の使用方法の説明になります。
Sub HexString()
Dim idx1 As Long
Dim last_row As Long
Dim ws As Worksheet
Set ws = ActiveSheet()
last_row = GetBlankRow(ws) ' 最終行を取得
For idx1 = 2 To last_row
' 16進数へ変換
Cells(idx1, 2) = Hex(Cells(idx1, 1))
' 16進数へ変換(4桁、左をゼロで埋める)
Cells(idx1, 3).NumberFormatLocal = "@"
Cells(idx1, 3) = "0x" & Right(Format(Hex(Cells(idx1, 1)), "0000"), 4)
' 16進数へ変換(8桁、左をゼロで埋める)
Cells(idx1, 4).NumberFormatLocal = "@"
Cells(idx1, 4) = "0x" & Right(Format(Hex(Cells(idx1, 1)), "00000000"), 8)
Next idx1
End Sub
変換結果
A列の数値をB列以降に変換しています。



コメント