重複するオブジェクト名・プロパティ名などを省略できるWithステートメントの使い方です。
Withステートメントの使い方

アクティブセルの値を、ひとつ右のセルにコピーするというプログラムで考えてみます。
コピー方法はこの記事のものを使います。

ActiveCell.Next = ActiveCell.Valueというコードを実行すると、コピーが実行されることが確認できます。

コード内には二回ActiveCellが登場していますが、

この状態からコードの前にWith ActiveCellを付け、

コードの後にはEnd Withを付けます。WithとWithでコードを挟んだ状態です。

このWith間では、最初に指定したWithの後ろのActiveCellが省略可能になります。
つまり、以下のコードでActiveCell.Next = ActiveCell.Valueと同じ意味になります。
つまり、以下のコードでActiveCell.Next = ActiveCell.Valueと同じ意味になります。
' vba
' 省略する文字を宣言
With ActiveCell
' .から始めると、ActiveCellが頭に付いたことになる
.Next = .Value
End With

なおWithを使う時は、囲んだコードはTabを押して一段下げておくと見やすいコードになります。

Excel(エクセル):重複、一意
重複データ、重複していない(一意の)データ関連の操作、設定まとめです。
重複・一意
条件付き書式やCountIf関数を使用し、重複(一意)のデータだけを強調・洗い出しする方法です。
データの入力規則でCount...
コメント