言語ごとに書き方が若干異なる部分を中心にまとめています。
比較演算子
演算子 | 説明 |
= | 等しい |
<> | 等しくない |
> | より大きい |
>= | 以上 |
< | より小さい |
<= | 以下 |
論理演算子
演算子 | 説明 |
And | And |
Or | Or |
Xor | Xor |
Not | Not |
If (True And True) Then print("And") End If
If (True Or False) Then print("Or") End If
If (True Xor True) Then print("Xor") End If
If (Not False) Then print("Not") End If
繰り返し
For i = 1 To 10 Print (i) Next
For i = 1 To 10 Step 2 Print (i) Next
For i = 10 To 1 Step -1 Print (i) Next
配列
Dim items() As Variant items = Array(1, 2, 3, 4, 5) For Each item in items Print item Next item
予約語
ThisWorkBook:マクロを実行しているワークブック ActiveWorkBook:現在表示しているワークブック ActiveWorkSheet:現在表示しているワークシート
マクロの高速化
画面の描画を停止させることで、マクロの実行を高速化させることが出来る
Application.ScreenUpdating = False ~実行させたいマクロ~ Application.ScreenUpdating = True
マクロの高速化2
自動計算を止めることで、値を変更した際に再計算が走らず高速化される
tmp_calc = Application.Calculation Application.Calculation = xlCalculationManual ~実行させたいマクロ~ Application.Calculation = tmp_calc
最終行の取得
上から下に検索
Cells(1, 1).End(xlDown).Row
下から上に検索
Cells(Rows.Count, 1).End(xlUp).Row
コメント