Sub f1()
m = InputBox("Please enter your number!")
For i = 1 To m
For j = 1 To m
If i = j Then ' 对角线
Cells(i, j).Value = i * i
Cells(i, j).Interior.ColorIndex = 35
End If
If i > j Then ' 下三角
Cells(i, j).Value = i * (i - 1) + j
Cells(i, j).Interior.ColorIndex = 28
End If
If i < j Then ' 上三角
Cells(i, j).Value = (j - 1) * (j - 1) + i
Cells(i, j).Interior.ColorIndex = 14
End If
Next j
Next i
End Sub