Sub Sample1()
Dim i As Long, Result As Long
For i = 2 To 21
If Format(Cells(i, 1).Value, "aaaa") = "日曜日" Then
Result = Result + Cells(i, 3).Value
End If
Next i
Range("F2").Value = Result
End Sub
「Dim i , Result As Long」という宣言では、変数「i」はバリアント型になります。
変数の型がわからないときは、型宣言(As ○○)を省略して、バリアント型変数を使ってもいいです。なぜバリアント型を使うのがいいのか。バリアント型に関する「速度が遅い」などのデメリットが、現在では適切ではないことなどは、ベーシックで学習します。
Sub Sample1()
Dim i As Long, Result As Long
For i = 2 To 21
If IsDate(Cells(i, 1).Value) And Format(Cells(i, 1).Value, "aaaa") = "日曜日" Then
Result = Result + Cells(i, 3).Value
End If
Next i
Range("F2").Value = Result
End Sub
C列のデータが数値形式かどうかの確認なども考えられます。
Sub Sample1()
Dim i As Long, Result As Long
For i = 2 To 21
If Format(Cells(i, 1).Value, "aaaa") = "日曜日" Then
If IsNumeric(Cells(i, 3).Value) Then
Result = Result + Cells(i, 3).Value
End If
End If
Next i
Range("F2").Value = Result
End Sub
Sub Sample2()
Dim i As Long
For i = 2 To 21
If Cells(i, 2).Value = "田中" Then
Cells(i, 1).Font.ColorIndex = 3
Cells(i, 2).Font.ColorIndex = 3
Cells(i, 3).Font.ColorIndex = 3
End If
Next i
End Sub