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?

More than 1 year has passed since last update.

Excel VBA シートを指定したセルの値の取得方法

Posted at

初めに

ExcelでVBAを書く際に、シート名を指定してセルの値を取得する方法について記載します。

やり方

まずは基本的な書き方についてです。

基本的な書き方
Worksheets("対象のシート名").Range("対象のセル").Value
Worksheets("対象のシート名").Cells(行番号, 列番号).Value

では実際の値を取得してみましょう。
以下のようにシート名「実行」にある「セル取得」ボタンを実行するとシート名「ターゲット」の「A1」「A2」の値を取得するVBAを書くことを想定します。

シート名「実行
image.png

シート名「ターゲット」
image.png
コードは以下のようになります。

コード
Sub GetAnoterSheetValue_Btn()
    Debug.Print (Worksheets("ターゲット").Range("A1").Value)
    Debug.Print (Worksheets("ターゲット").Cells(1, 1).Value)
    Debug.Print (Worksheets("ターゲット").Range("A2").Value)
    Debug.Print (Worksheets("ターゲット").Cells(2, 1).Value)
End Sub

上記の実行結果です。

実行結果
ターゲットシートのA1
ターゲットシートのA1
ターゲットシートのA2
ターゲットシートのA2

以上になります。

最後に

ここまで見ていただきありがとうございます。

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?