Excel VBAの開発には、Visual Basci Editorを使います。
ツール => マクロ => VBE

プログラムを書いていくには、標準モジュールを使います。プロシージャーはSubから書き始めていきましょう。
Sub HelloWorld()
MsgBox ("hello wolrd")
End Sub
セルにデータを書き込む
Sub CellChange()
Worksheets("Sheet1").Range("A1").Value = "hello"
Range("A2").Value = "hello2"
Cells(3, 1).Value = "hello3"
End Sub
Sub CellChange()
Range("A1", "B3").Value = "hello"
Range("A5:C7").Value = "hello2"
Range("4:4").Value = "row 4"
Range("C:C").Value = "Column C"
End Sub
withで複数の命令を重ねる
Sub WithTest()
With Range("A1")
.Value = "hello"
With .Font
.Bold = True
.Size = 16
End With
.Interior.Color = vbRed
End With
End Sub
値の取得
Sub GetTest()
MsgBox (Range("A1").Value)
End Sub
メソッドで処理を呼び出し
Sub MethodTest()
'Range("B3").Delete shift:=xlShiftUp
Worksheets.Add after:=Worksheets("sheet1"), Count:=3
End Sub
変数計算
Sub VariableTest()
Dim x As Integer
x = 10 + 5
x = x + 1
'Range("A1").Value = x
Debug.Print x
End Sub
配列
Sub VariableTest()
Dim sales As Variant
sales = Array(200, 150, 300)
Debug.Print sales(2)
End Sub
条件分岐
Sub IfTest()
If Range("A1").Value > 15 Then
Range("A2").Value = "OK"
Else
Range("A2").Value = "NG!"
End If
End Sub