
Private Sub Workbook_Open() Dim loopA As Integer
Dim loopB As Integer Dim loopNum As Integer
Dim topCell As Range loopNum = CInt(InputBox("input number", "title")) Cells.Select
'Selection.ClearContents
Selection.Delete Shift:=xlUp For loopA = To loopNum If loopA = Then
Cells(loopA, loopNum).Value = ""
Cells(loopA, loopNum).Interior.Color =
Set topCell = Cells(loopA, loopNum)
GoTo nextFor Else
For loopB = To loopNum * -
Call setRangeValue(Cells(loopA, loopB)) If loopA = loopNum Then
If Len(Cells(loopA, loopB).Value) > Then
Cells(loopA, loopB).Interior.Color =
End If
End If
Next loopB
End If
nextFor: Next loopA Cells.Select
'Cells.EntireColumn.AutoFit
Selection.ColumnWidth =
Cells.EntireRow.AutoFit
'Selection.RowHeight = 4 topCell.Activate
topCell.Select End Sub Public Sub setRangeValue(rag As Range) Dim bfLeftRange As Range
Dim bfRightRange As Range
Dim leftVal As Double
Dim rightVal As Double If rag.Column = Then
Set bfLeftRange = Cells(rag.Row - , rag.Column)
Else
Set bfLeftRange = Cells(rag.Row - , rag.Column - )
End If Set bfRightRange = Cells(rag.Row - , rag.Column + ) If Len(bfLeftRange.Value) = And Len(bfRightRange.Value) = Then
rag.Value = ""
GoTo SubEnd
Else
leftVal = CDbl(bfLeftRange.Value)
rightVal = CDbl(bfRightRange.Value)
rag.Value = leftVal + rightVal
If rag.Value = "" Then
rag.Interior.Color =
End If End If SubEnd: End Sub