趣味のエクセルで当てよう!ロト・ナンバーズ

当選狙いで、ナンバーズ4をメインにロト、ビンゴ5などの各種データリストや、それらの分析用エクセルVBAなどについて書いてます。

マクロ作成方法12(マクロ自動記録)

マクロが自動で記録できるのは便利ですね!
下の様に両脇の罫線を赤色、下線を赤色点線や実線にするマクロを自動記録して見ました。(点線は元々点線なので赤色にします)



Sub Macro1() ’マクロ1 セルBN4933の両側と下を赤色にする自動記録マクロ
    Selection.Borders(xlDiagonalDown).LineStyle = xlNone
    Selection.Borders(xlDiagonalUp).LineStyle = xlNone
    With Selection.Borders(xlEdgeLeft) ’セルの左の部分です
        .LineStyle = xlContinuous
        .Color = -16776961
        .TintAndShade = 0
        .Weight = xlThin
    End With
    With Selection.Borders(xlEdgeTop) ’セルの上の部分です
        .LineStyle = xlContinuous
        .ColorIndex = xlAutomatic
        .TintAndShade = 0
        .Weight = xlHairline
    End With
    With Selection.Borders(xlEdgeBottom) ’セルの下の部分です
        .LineStyle = xlContinuous
        .Color = -16776961
        .TintAndShade = 0
        .Weight = xlHairline
    End With
    With Selection.Borders(xlEdgeRight) ’セルの右の部分です
        .LineStyle = xlContinuous
        .Color = -16776961
        .TintAndShade = 0
        .Weight = xlThin
    End With
    Selection.Borders(xlInsideVertical).LineStyle = xlNone
    Selection.Borders(xlInsideHorizontal).LineStyle = xlNone
End Sub


Sub Macro2() ’マクロ2 セルBN4935の両側と下(実線にする)を赤色にする自動記録マクロ
    Selection.Borders(xlDiagonalDown).LineStyle = xlNone
    Selection.Borders(xlDiagonalUp).LineStyle = xlNone
    With Selection.Borders(xlEdgeLeft)
        .LineStyle = xlContinuous
        .Color = -16776961
        .TintAndShade = 0
        .Weight = xlThin
    End With
    With Selection.Borders(xlEdgeTop)
        .LineStyle = xlContinuous
        .ColorIndex = xlAutomatic
        .TintAndShade = 0
        .Weight = xlHairline
    End With
    With Selection.Borders(xlEdgeBottom)
        .LineStyle = xlContinuous
        .Color = -16776961
        .TintAndShade = 0
        .Weight = xlThin
    End With


    With Selection.Borders(xlEdgeRight)
        .LineStyle = xlContinuous
        .Color = -16776961
        .TintAndShade = 0
        .Weight = xlThin
    End With
    Selection.Borders(xlInsideVertical).LineStyle = xlNone
    Selection.Borders(xlInsideHorizontal).LineStyle = xlNone
End Sub
ーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーーー
 上の自動記録から必要な部分をさがし、マクロ作成方法11のストレート回数表示5回目と6回目の表示を下の様に改良しました。(最高6回なので7回目は作って無いですw)
私は必要な部分かどうかは試行錯誤しています。w



   caler = WorksheetFunction.CountIf(Range(Cells(2, 66), Cells(i, 66)), Cells(i, 66))
   
              Set stcolo = Cells(i, 66)
            stcolo.Borders(xlEdgeLeft).ColorIndex = 1
          If caler = 2 Then 'ストレート2回目緑色にする
                      stcolo.Borders(xlEdgeLeft).ColorIndex = 4


          ElseIf caler = 3 Then 'ストレート3回目赤色にする
                    stcolo.Borders(xlEdgeLeft).ColorIndex = 3
          
          ElseIf caler = 4 Then 'ストレート4回目両脇赤色にする
        
             stcolo.Borders(xlEdgeLeft).ColorIndex = 3
             stcolo.Borders(xlEdgeRight).ColorIndex = 3
         
          ElseIf caler = 5 Then 'ストレート5回目両脇赤色下線赤色にする
            
             stcolo.Borders(xlEdgeLeft).ColorIndex = 3
             stcolo.Borders(xlEdgeRight).ColorIndex = 3
             stcolo.Borders((xlEdgeBottom)).ColorIndex = 3
            
          ElseIf caler = 6 Then 'ストレート6回目両脇と下線赤色実線にする
             stcolo.Borders(xlEdgeLeft).ColorIndex = 3
             stcolo.Borders(xlEdgeRight).ColorIndex = 3
             stcolo.Borders((xlEdgeBottom)).ColorIndex = 3
             stcolo.Borders((xlEdgeBottom)).Weight = xlThin
                
          End If