0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

VBAで数字をゼロ埋めする

Posted at

VBAで数字をゼロ埋めする方法として、まずFormatを利用する方法があります。

' 固定長の場合
Debug.Print Format(123, "00000") ' => 00123

' 可変長の場合
Debug.Print Format(456, String(5, "0")) ' => 00456

あるいは、Rightを使う方法もあります。こちらはイディオム的ですね。

' 固定長の場合
Debug.Print Right("00000" & 123, 5) ' => 00123

' 可変長の場合
Dim n As Long
n = 5
Debug.Print Right(String(n, "0") & 456, n) ' => 00456

環境情報

image.png

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?