かぐやのパソコン活動!

アイカツ好きのパソコン活動!

VBA練習2!

パンは何も付けない派!

かぐやです!

 

今日も今日とてパソコン活動!パソ活!

 

今日はExcelの神髄さんのVBA練習問題を解きました!

 

練習問題7はぼけーっとしてて飛ばしちゃいました(笑)

 

練習8の表示形式を変える問題はFormat関数でやったらA列の表示形式がうまく変わらなかったので調べて解きました(*ノωノ)

 

NumberFormatlocal関数を使って解くみたいですね!

Excelの神髄さんは本当に勉強になります!

 

みなさんも是非チャレンジしてみてはいかがでしょうか?

 

下記は自分が実際に記述したコードになりますヾ(≧▽≦)ノ

Sub 練習4()
    Dim i As Long
    For i = 2 To Cells(Rows.Count, 1).End(xlUp).Row
        If Cells(i, 2) < Cells(i, 3) Then
            Cells(i, 4) = "×"
            Cells(i, 5) = Cells(i, 2) Mod Cells(i, 3)
        Else
            Cells(i, 4) = Cells(i, 2) \ Cells(i, 3)
            Cells(i, 5) = Cells(i, 2) Mod Cells(i, 3)
        End If
        Next i
End Sub
Sub 練習5()
    Dim i As Long
    For i = 2 To Cells(Rows.Count, 1).End(xlUp).Row
        Cells(i, 4) = Cells(i, 3) / Cells(i, 2)
        Select Case Cells(i, 4)
            Case Is >= 1.05
                Cells(i, 5) = "S"
            Case Is >= 1
                Cells(i, 5) = "A"
            Case Is >= 0.95
                Cells(i, 5) = "B"
            Case Is >= 0.9
                Cells(i, 5) = "C"
            Case Else
                Cells(i, 5) = "D"
        End Select
    Next i
End Sub
Sub 練習6()
    Dim i As Long
    Dim Sum As Long
    For i = 2 To Cells(Rows.Count, 1).End(xlUp).Row
        Cells(i, 4) = Cells(i, 2) * Cells(i, 3)
        Sum = Sum + Cells(i, 4)
    Next i
    Cells(i, 4) = Sum
End Sub
Sub 練習8()
    Dim i As Long
    For i = 2 To Cells(Rows.Count, 1).End(xlUp).Row
        Cells(i, 4) = Cells(i, 2) * Cells(i, 3)
    Next i
        Columns(1).NumberFormatLocal = "yyyy/mm/dd"
        Columns(4).NumberFormatLocal = "#,##0"
End Sub