VBA体験講座
AxiZ沖縄では、学校見学者に対して 希望があれば1時間程度もプログラミングの体験講座も実施しています。
内容としては、Excelに付随しているプログラミング言語であるVBAを用いて、
簡単なExcel操作のプログラムを作る、というものです。
体験講座用としてスライドの資料を作成したので、その内容をアップします。
家や職場でExcelを使える環境があって、 ちょっとプログラミングに興味がある方、を試してみたいという方は是非参考にしてみてください。
やりたいことの概要はこちら にも載せています。
ソースコードも載せておきます。
'step1 Sub 初めてのプログラム() MsgBox ("こんにちは") End Sub 'step3 Sub 初めてのプログラム() Dim num As Integer num = 100 MsgBox (num) End Sub 'step4 Sub 初めてのプログラム() Dim sum As Integer Dim avg As Integer sum = 100 + 90 + 80 avg = sum / 3 MsgBox (sum) MsgBox (avg) End Sub 'step5 Sub 初めてのプログラム() Dim sum As Integer Dim avg As Integer sum = Cells(10, 3).Value + Cells(10, 4).Value + Cells(10, 5).Value avg = sum / 3 MsgBox (sum) MsgBox (avg) End Sub 'step6 Sub 初めてのプログラム() Dim sum As Integer Dim avg As Integer sum = Cells(10, 3).Value + Cells(10, 4).Value + Cells(10, 5).Value avg = sum / 3 Cells(10, 6).Value = sum Cells(10, 7).Value = avg End Sub 'step7 Sub 初めてのプログラム() Dim sum As Integer Dim avg As Integer Dim score As String sum = Cells(10, 3).Value + Cells(10, 4).Value + Cells(10, 5).Value avg = sum / 3 Cells(10, 6).Value = sum Cells(10, 7).Value = avg If avg >= 80 Then score = "A" End If Cells(10, 8).Value = score End Sub 'step8 Sub 初めてのプログラム() Dim sum As Integer Dim avg As Integer Dim score As String sum = Cells(10, 3).Value + Cells(10, 4).Value + Cells(10, 5).Value avg = sum / 3 Cells(10, 6).Value = sum Cells(10, 7).Value = avg If avg >= 80 Then score = "A" Else score = "E" End If Cells(10, 8).Value = score End Sub 'step9 Sub 初めてのプログラム() ' 省略 If avg >= 80 Then score = "A" ElseIf avg >= 70 Then score = "B" ElseIf avg >= 60 Then score = "C" ElseIf avg >= 50 Then score = "D" Else score = "E" End If Cells(10, 8).Value = score End Sub 'step10 Sub 初めてのプログラム() Dim sum As Integer Dim avg As Integer Dim score As String Dim i As Integer For i = 10 To 14 sum = Cells(i, 3).Value + Cells(i, 4).Value + Cells(i, 5).Value avg = sum / 3 Cells(i, 6).Value = sum Cells(i, 7).Value = avg ' IF文省略 Cells(i, 8).Value = score Next End Sub