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

【VBA】Withでコードをまとめる

Posted at

◆Withの使い方

Withを使うとコードの共通部分をまとめることができる。
オブジェクトのプロパティを一括で設定する際に便利。

Withの使い方
Sub withSample()
    '太字、20pt、赤で塗りつぶし
    Range("A1").Value = "sample"
    Range("A1").Font.Bold = True
    Range("A1").Font.Size = 20
    Range("A1").Interior.Color = vbRed
End Sub

Sub withSample2()
    '上記はWithを用いてまとめることができる
    With Range("A1")
        .Value = "sample"
        .Font.Bold = True
        .Font.Size = 20
        .Interior.Color = vbRed
    End With
End Sub
1
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
1
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?