Sub MoHinhMau()
Dim DesTemp As Range, Des As Range
On Error Resume Next
Set DesTemp = Application.InputBox("Ch" & ChrW(7885) & "n ô t" & ChrW(7841) & _
"o mô hình m" & ChrW(7851) & "u", "Mô hình m" & ChrW(7851) & _
"u", Default:=ActiveWindow.ActiveCell.Address, Type:=8)
If Err.Number <> 0 Then Exit Sub
Application.ScreenUpdating = False
Application.DisplayStatusBar = False
Application.Calculation = xlCalculationManual
Application.EnableEvents = False
ActiveSheet.DisplayPageBreaks = False
If IsArray(DesTemp) = True Then
Set Des = DesTemp.Cells(1, 1)
Else
Set Des = DesTemp
End If
With Des.Resize(11, 7)
.Clear
.HorizontalAlignment = xlCenter
.VerticalAlignment = xlCenter
End With
With Des.Resize(9, 5)
.Borders(xlEdgeLeft).LineStyle = xlContinuous
.Borders(xlEdgeRight).LineStyle = xlContinuous
.Borders(xlEdgeTop).LineStyle = xlContinuous
.Borders(xlEdgeBottom).LineStyle = xlContinuous
.Borders(xlInsideVertical).LineStyle = xlContinuous
.Borders(xlInsideHorizontal).LineStyle = xlContinuous
End With
With Des.Offset(10, 1).Resize(, 4)
.Borders(xlEdgeLeft).LineStyle = xlContinuous
.Borders(xlEdgeRight).LineStyle = xlContinuous
.Borders(xlEdgeTop).LineStyle = xlContinuous
.Borders(xlEdgeBottom).LineStyle = xlContinuous
.Borders(xlInsideVertical).LineStyle = xlContinuous
.Borders(xlInsideHorizontal).LineStyle = xlContinuous
.Interior.Color = 65535
End With
With Des.Offset(2, 6).Resize(7)
.Borders(xlEdgeLeft).LineStyle = xlContinuous
.Borders(xlEdgeRight).LineStyle = xlContinuous
.Borders(xlEdgeTop).LineStyle = xlContinuous
.Borders(xlEdgeBottom).LineStyle = xlContinuous
.Borders(xlInsideVertical).LineStyle = xlContinuous
.Borders(xlInsideHorizontal).LineStyle = xlContinuous
.Interior.Color = 65535
End With
With Des.Offset(3, 2).Resize(6, 3)
.Borders(xlEdgeLeft).Weight = xlMedium
.Borders(xlEdgeRight).Weight = xlMedium
.Borders(xlEdgeTop).Weight = xlMedium
.Borders(xlEdgeBottom).Weight = xlMedium
.Borders(xlInsideVertical).Weight = xlMedium
.Borders(xlInsideHorizontal).Weight = xlMedium
.Interior.Color = 65280
End With
With Des.Resize(2, 1)
.MergeCells = True
.FormulaR1C1 = "Day"
.Font.Bold = True
End With
With Des.Resize(11, 7)
.Cells(1, 2).FormulaR1C1 = "L" & ChrW(432) & ChrW(7907) & "ng (Kg)"
.Cells(1, 2).Font.Bold = True
.Cells(1, 3).FormulaR1C1 = "10000"
.Cells(1, 4).FormulaR1C1 = "4900"
.Cells(1, 5).FormulaR1C1 = "4900"
.Cells(2, 2).FormulaR1C1 = "Kho"
.Cells(2, 2).Font.Bold = True
.Cells(2, 3).FormulaR1C1 = "1250"
.Cells(2, 4).FormulaR1C1 = "652"
.Cells(2, 5).FormulaR1C1 = "590"
.Cells(3, 1).FormulaR1C1 = "Yêu C" & ChrW(7847) & "u" & Chr(10) & "(Kg)"
.Cells(3, 1).Font.Bold = True
.Cells(3, 2).FormulaR1C1 = "So luong" & Chr(10) & "-----------" & "Tip"
.Cells(3, 2).Font.Bold = True
.Cells(3, 3).FormulaR1C1 = "2"
.Cells(3, 4).FormulaR1C1 = "6"
.Cells(3, 5).FormulaR1C1 = "8"
.Cells(3, 7).FormulaR1C1 = "K" & ChrW(7871) & "t qu" & ChrW(7843)
.Cells(3, 7).Font.Bold = True
.Cells(4, 1).FormulaR1C1 = "4000"
.Cells(4, 2).FormulaR1C1 = "91"
.Cells(4, 3).FormulaR1C1 = "0"
.Cells(4, 4).FormulaR1C1 = "1"
.Cells(4, 5).FormulaR1C1 = "0"
.Cells(4, 7).FormulaR1C1 = "=RC[-5]*SUMPRODUCT(R[-3]C[-4]:R[-3]C[-2]*R[-1]C[-4]:R[-1]C[-2]*RC[-4]:RC[-2]/R[-2]C[-4]:R[-2]C[-2])"
.Cells(5, 1).FormulaR1C1 = "2000"
.Cells(5, 2).FormulaR1C1 = "127"
.Cells(5, 3).FormulaR1C1 = "1"
.Cells(5, 4).FormulaR1C1 = "0"
.Cells(5, 5).FormulaR1C1 = "0"
.Cells(5, 7).FormulaR1C1 = "=RC[-5]*SUMPRODUCT(R[-4]C[-4]:R[-4]C[-2]*R[-2]C[-4]:R[-2]C[-2]*RC[-4]:RC[-2]/R[-3]C[-4]:R[-3]C[-2])"
.Cells(6, 1).FormulaR1C1 = "25000"
.Cells(6, 2).FormulaR1C1 = "153"
.Cells(6, 3).FormulaR1C1 = "2"
.Cells(6, 4).FormulaR1C1 = "0"
.Cells(6, 5).FormulaR1C1 = "2"
.Cells(6, 7).FormulaR1C1 = "=RC[-5]*SUMPRODUCT(R[-5]C[-4]:R[-5]C[-2]*R[-3]C[-4]:R[-3]C[-2]*RC[-4]:RC[-2]/R[-4]C[-4]:R[-4]C[-2])"
.Cells(7, 1).FormulaR1C1 = "5200"
.Cells(7, 2).FormulaR1C1 = "173"
.Cells(7, 3).FormulaR1C1 = "2"
.Cells(7, 4).FormulaR1C1 = "0"
.Cells(7, 5).FormulaR1C1 = "0"
.Cells(7, 7).FormulaR1C1 = "=RC[-5]*SUMPRODUCT(R[-6]C[-4]:R[-6]C[-2]*R[-4]C[-4]:R[-4]C[-2]*RC[-4]:RC[-2]/R[-5]C[-4]:R[-5]C[-2])"
.Cells(8, 1).FormulaR1C1 = "7200"
.Cells(8, 2).FormulaR1C1 = "233"
.Cells(8, 3).FormulaR1C1 = "2"
.Cells(8, 4).FormulaR1C1 = "0"
.Cells(8, 5).FormulaR1C1 = "0"
.Cells(8, 7).FormulaR1C1 = "=RC[-5]*SUMPRODUCT(R[-7]C[-4]:R[-7]C[-2]*R[-5]C[-4]:R[-5]C[-2]*RC[-4]:RC[-2]/R[-6]C[-4]:R[-6]C[-2])"
.Cells(9, 1).FormulaR1C1 = "42000"
.Cells(9, 2).FormulaR1C1 = "277"
.Cells(9, 3).FormulaR1C1 = "0"
.Cells(9, 4).FormulaR1C1 = "2"
.Cells(9, 5).FormulaR1C1 = "1"
.Cells(9, 7).FormulaR1C1 = "=RC[-5]*SUMPRODUCT(R[-8]C[-4]:R[-8]C[-2]*R[-6]C[-4]:R[-6]C[-2]*RC[-4]:RC[-2]/R[-7]C[-4]:R[-7]C[-2])"
.Cells(11, 2).FormulaR1C1 = "Thua"
.Cells(11, 2).Font.Bold = True
.Cells(11, 3).FormulaR1C1 = "=R[-9]C-SUMPRODUCT(R[-7]C[-1]:R[-2]C[-1]*R[-7]C:R[-2]C)"
.Cells(11, 4).FormulaR1C1 = "=R[-9]C-SUMPRODUCT(R[-7]C[-2]:R[-2]C[-2]*R[-7]C:R[-2]C)"
.Cells(11, 5).FormulaR1C1 = "=R[-9]C-SUMPRODUCT(R[-7]C[-3]:R[-2]C[-3]*R[-7]C:R[-2]C)"
.Columns.AutoFit
.Rows.AutoFit
.Columns(6).EntireColumn.ColumnWidth = 3
End With
Des.Offset(, 2).Resize(, 3).NumberFormat = "_(* #,##0_);_(* (#,##0);_(* ""-""??_);_(@_)"
Des.Offset(2).Resize(6).NumberFormat = "_(* #,##0_);_(* (#,##0);_(* ""-""??_);_(@_)"
Des.Offset(2, 6).Resize(6).NumberFormat = "_(* #,##0_);_(* (#,##0);_(* ""-""??_);_(@_)"
Application.ScreenUpdating = True
Application.DisplayStatusBar = True
Application.Calculation = xlCalculationAutomatic
Application.EnableEvents = True
ActiveSheet.DisplayPageBreaks = False
End Sub