|
1.ALT+F11キーで、VBEを起動
2.プロジェクトウィンドウのSheet1 を Wクリック
3.中央の真っ白なウィンドウ(コードウィンドウ)に以下のコードをコピペ
(注)もし、動かないときは、デザインモードになっていないか確認する。
Private Sub Worksheet_Change(ByVal Target As Range)
Dim myRange As Range
If Target.Address <> Range("C1").Address Then Exit Sub
If Target.Value < 1 Or Target.Value > 65500 Then Exit Sub
'クリア
Range("E8:I65536").ClearFormats
Range("E8:I65536").ClearContents
'罫線
On Error Resume Next
Set myRange = Range("E7:I7")
With myRange.Borders(xlEdgeLeft)
.LineStyle = xlContinuous
.Weight = xlThin
.ColorIndex = xlAutomatic
End With
With myRange.Borders(xlEdgeTop)
.LineStyle = xlContinuous
.Weight = xlThin
.ColorIndex = xlAutomatic
End With
With myRange.Borders(xlEdgeBottom)
.LineStyle = xlContinuous
.Weight = xlThin
.ColorIndex = xlAutomatic
End With
With myRange.Borders(xlEdgeRight)
.LineStyle = xlContinuous
.Weight = xlThin
.ColorIndex = xlAutomatic
End With
With myRange.Borders(xlInsideVertical)
.LineStyle = xlContinuous
.Weight = xlThin
.ColorIndex = xlAutomatic
End With
With myRange.Borders(xlInsideHorizontal)
.LineStyle = xlContinuous
.Weight = xlThin
.ColorIndex = xlAutomatic
End With
'コピー
myRange.Copy myRange.Resize(Range("C1").Value)
On Error GoTo 0
End Sub
|
|