Excelで生産予定・実績表を作ってみよう

Step 13 罫線を引く

表の格子細線と外枠の太線を引きます。


Homeに戻る > Excelでアプリケーションソフト > 生産予定・実績表アプリ

シートのVBAコード

下記に変更してください。

Private Sub CommandButton1_Click()
    Range("L12").Select
    If Not SetDataCheck Then
        Exit Sub
    End If
        
    nowbusy = True
    
    ExNewSheetMake
    
    Worksheets("機種マスター").Select
    Range("L12").Select
    
    '日付をセット
    ExDaySet
    '機種マスターの機種名をセットする
    ExMasterSet
    '罫線を引く
    Exkeisen

    nowbusy = False
End Sub

下記を追加してください。

'罫線を引く
Private Sub Exkeisen()
    Dim lastday As Integer
    Dim destrow As Long
    Dim destcol As Long
    Dim lastrow As Long
    
    'セット先
    destrow = Range(Range("L4")).Row
    destcol = Range(Range("L4")).Column
    
    '最終日を取得
    lastday = MonthLastDay(Range("L9"), Range("L10"))
    '最終行を取得
    lastrow = ActiveSheet.Range("D65536").End(xlUp).Row - 3
    
    Worksheets(Sheets.Count).Select
    '格子罫線を書く
    Worksheets(Sheets.Count).Range(Worksheets(Sheets.Count).Cells(destrow, destcol), _
    Worksheets(Sheets.Count).Cells(destrow + lastrow, destcol + lastday + 6)).Select
    Selection.Borders.Weight = xlThin
    Selection.Borders.LineStyle = xlContinuous
    
    '外枠を太線で書く
    DoWakuKeisen
    
    '項目の下の太線を書く
    Worksheets(Sheets.Count).Range(Worksheets(Sheets.Count).Cells(destrow, destcol), _
    Worksheets(Sheets.Count).Cells(destrow, destcol + lastday + 6)).Select
    Selection.Borders(xlEdgeBottom).Weight = xlThick
    Selection.Borders(xlEdgeBottom).LineStyle = xlContinuous
    
    '予定数~開始日の所に格子罫線を書く
    Worksheets(Sheets.Count).Range(Worksheets(Sheets.Count).Cells(destrow - 1, destcol + 3), _
    Worksheets(Sheets.Count).Cells(destrow - 1, destcol + 5)).Select
    Selection.Borders.Weight = xlThin
    Selection.Borders.LineStyle = xlContinuous
    '下側の線を細線にする
    Selection.Borders(xlEdgeBottom).Weight = xlThin
    Selection.Borders(xlEdgeBottom).LineStyle = xlContinuous
    '左側の線を太線にする
    Selection.Borders(xlEdgeLeft).Weight = xlThick
    Selection.Borders(xlEdgeLeft).LineStyle = xlContinuous
    '上側の線を太線にする
    Selection.Borders(xlEdgeTop).Weight = xlThick
    Selection.Borders(xlEdgeTop).LineStyle = xlContinuous
    '右側の線を太線にする
    Selection.Borders(xlEdgeRight).Weight = xlThick
    Selection.Borders(xlEdgeRight).LineStyle = xlContinuous
    
    '日付前の線を太線にする
    Worksheets(Sheets.Count).Range(Worksheets(Sheets.Count).Cells(destrow, destcol + 5), _
    Worksheets(Sheets.Count).Cells(destrow + lastrow, destcol + 5)).Select
    Selection.Borders(xlEdgeRight).Weight = xlThick
    Selection.Borders(xlEdgeRight).LineStyle = xlContinuous
    
    Worksheets(Sheets.Count).Range("A1").Select
End Sub



モジュールコード

下記を追加してください。

'外枠 太線
Public Sub DoWakuKeisen()
'    Range(srange).Select
   
    '左罫線
    With Selection.Borders(xlEdgeLeft)
        .Weight = xlThick
        .LineStyle = xlContinuous
    End With
    '上罫線
    With Selection.Borders(xlEdgeTop)
        .Weight = xlThick
        .LineStyle = xlContinuous
    End With
    '右罫線
    With Selection.Borders(xlEdgeRight)
        .Weight = xlThick
        .LineStyle = xlContinuous
    End With
    '下罫線
    With Selection.Borders(xlEdgeBottom)
        .Weight = xlThick
        .LineStyle = xlContinuous
    End With
End Sub

実行結果の画面

外枠を太線に、中の線は細線にしています。



Homeに戻る > Excelでアプリケーションソフト > 生産予定・実績表アプリ

■■■
このサイトの内容を利用して発生した、いかなる問題にも一切責任は負いませんのでご了承下さい
■■■
当ホームページに掲載されているあらゆる内容の無許可転載・転用を禁止します


Copyright (c) Excel-Excel ! All rights reserved