[VBA]色々 [VBA]
■定数宣言
Const 定数名 [As データ型] = "定数の値"
■条件分岐
If 条件式1 Then
ElseIf 条件式2 Then
Else
End If
・条件式:And Or Not = <>
■ループ:For-Next
For 変数 = 開始数値 To 終了数値 [カウンターに加算する数値]
'処理
Next
・Exit For
ループを抜ける。break
■ループ:Do-Loop
Do [While/Until 条件式]
'処理
Loop
・Exit Do
ループを抜ける。
■最終行、最終列取得
行 指定セルからCtrl+↓ Cells(1,1).End(xlDown).Row
行 指定行の下から上 Cells(Rows.Count, 1).End(xlUp).Row
列 指定セルからCtrl+→ Cells(1, 1).End(xlToRight).Column
列 指定列の右から左 Cells(1, Columns.Count).End(xlToLeft).Column
シートの行数 Rows.Count
シートの列数 Columns.Count
選択セルの行番号 Row
選択セルの列番号 Column
■関数
Functionプロシージャ 戻り値あり
Subプロシージャ void型
Function func1(arg1 As Long, arg2 As Long) As Long
' プロシージャ名=戻り値
func1 = arg1 + arg2
End Function
Const 定数名 [As データ型] = "定数の値"
■条件分岐
If 条件式1 Then
ElseIf 条件式2 Then
Else
End If
・条件式:And Or Not = <>
■ループ:For-Next
For 変数 = 開始数値 To 終了数値 [カウンターに加算する数値]
'処理
Next
・Exit For
ループを抜ける。break
■ループ:Do-Loop
Do [While/Until 条件式]
'処理
Loop
・Exit Do
ループを抜ける。
■最終行、最終列取得
行 指定セルからCtrl+↓ Cells(1,1).End(xlDown).Row
行 指定行の下から上 Cells(Rows.Count, 1).End(xlUp).Row
列 指定セルからCtrl+→ Cells(1, 1).End(xlToRight).Column
列 指定列の右から左 Cells(1, Columns.Count).End(xlToLeft).Column
シートの行数 Rows.Count
シートの列数 Columns.Count
選択セルの行番号 Row
選択セルの列番号 Column
■関数
Functionプロシージャ 戻り値あり
Subプロシージャ void型
Function func1(arg1 As Long, arg2 As Long) As Long
' プロシージャ名=戻り値
func1 = arg1 + arg2
End Function
2018-12-26 08:10
nice!(0)