0
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

【VBA】CLngで文字列をLong型に変換!!

Last updated at Posted at 2023-02-17

CLngは、VBAのデータ型変換関数の一つで、Long型に変換するために使用されます。CLng関数を使用すると、文字列や数値など、異なるデータ型の値をLong型に変換することができます。

例えば、以下のようなコードを実行することができます。

Dim str As String
Dim num As Integer
Dim lngNum As Long

str = "1234"
num = 1234

lngNum = CLng(str) ' 文字列をLong型に変換
Debug.Print lngNum ' 結果:1234

lngNum = CLng(num) ' IntegerをLong型に変換
Debug.Print lngNum ' 結果:1234

上記の例では、CLng関数を使用して、文字列 "1234" と整数値 1234 をLong型に変換しています。Long型は、整数値を格納するために使用されるデータ型で、数値の範囲は-2,147,483,648から2,147,483,647までです。

VBAには、他にも多くのデータ型変換関数があります。例えば、CInt関数は整数型、CDbl関数は倍精度浮動小数点型、CStr関数は文字列型に変換するために使用されます。

0
1
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
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?