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 3 years have passed since last update.

Excel VBA 変数をセルに表示させるには?

Last updated at Posted at 2021-02-24

(注 この記事ではExcel 2019を使用しています)

 Excel VBAを学習すると、セルに値を代入する「Range("セル").value = 値」という構文を習うと思います。

'A1セルにExcelという文字(値)を代入する
Sub 代入()
    Range("A1").value = "Excel"
End sub

セルに値を代入する回数が少ないのならばこれでも良いのですが、代入する回数が多いと毎回「Range("セル").value = 値」と書くのは面倒くさいですよね。今回は変数をセルに代入する方法について解説したいと思います。

'まずA1セルに表示する変数「ランク」を定義する
'次に変数「ランク」にゴールドという文字(値)を代入する
Sub 代入()
    Set ランク = Range("A1")
    ランク.Value = "ゴールド" '.Valueは省略可能
End sub

これだけだとありがたみがないですが、if文を使うとありがたみがわかると思います。

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?