Sub test()
Application.ScreenUpdating = False
With Sheets("Header")
arr = .Range("B7", "M" & .Range("B" & .Rows.Count).End(xlUp).Row)
ReDim sn(1 To UBound(arr), 1 To 8)
For x = 1 To UBound(arr)
If x = 1 Then
sn(x, 1) = "No"
sn(x, 2) = "Invoice"
sn(x, 3) = "Account Code"
sn(x, 4) = "Begin Date"
sn(x, 5) = "End Date"
sn(x, 6) = "Before GST"
sn(x, 7) = "Sales Tax"
sn(x, 8) = "Amount"
Else
sn(x, 1) = x - 1
sn(x, 2) = "00" & arr(x, 1)
sn(x, 3) = arr(x, 2)
sn(x, 4) = arr(x, 4)
sn(x, 5) = arr(x, 5)
sn(x, 6) = arr(x, 10)
sn(x, 7) = arr(x, 11)
sn(x, 8) = arr(x, 12)
End If
Next
mstring = Format(.Range("E8"), "mmmm") & " " & Format(.Range("E8"), "yyyy")
End With
For i = 1 To Sheets.Count
If Sheets(i).Name = mstring Then
MsgBox "This month has been created before !"
Exit Sub
End If
Next
Sheets.Add After:=Sheets("Header")
ActiveSheet.Name = mstring
With Sheets(mstring)
.Range("A7").Resize(UBound(sn), 8) = sn
lr = 6 + UBound(sn)
.Range("B7", "B" & lr).NumberFormat = "0000000"
.Range("F8", "H" & lr).NumberFormat = ("$#.##0.00")
.Range("F" & lr + 1).FormulaR1C1 = "=SUM(R[-14]C:R[-1]C)"
.Range("F" & lr + 1).AutoFill Destination:=.Range("F" & lr + 1, "H" & lr + 1), Type:=xlFillDefault
With .Range("A7", "H" & lr).Borders(xlEdgeTop)
.LineStyle = xlContinuous
.ColorIndex = 0
.TintAndShade = 0
.Weight = xlThin
End With
With .Range("A7", "H" & lr).Borders(xlEdgeBottom)
.LineStyle = xlContinuous
.ColorIndex = 0
.TintAndShade = 0
.Weight = xlThin
End With
With .Range("A7", "H" & lr).Borders(xlEdgeRight)
.LineStyle = xlContinuous
.ColorIndex = 0
.TintAndShade = 0
.Weight = xlThin
End With
With .Range("A7", "H" & lr).Borders(xlEdgeLeft)
.LineStyle = xlContinuous
.ColorIndex = 0
.TintAndShade = 0
.Weight = xlThin
End With
With .Range("A7", "H" & lr).Borders(xlInsideHorizontal)
.LineStyle = xlContinuous
.ColorIndex = 0
.TintAndShade = 0
.Weight = xlThin
End With
With .Range("A7", "H" & lr).Borders(xlInsideVertical)
.LineStyle = xlContinuous
.ColorIndex = 0
.TintAndShade = 0
.Weight = xlThin
End With
With .Range("F" & lr + 1, "H" & lr + 1).Borders(xlEdgeBottom)
.LineStyle = xlDouble
.ColorIndex = 0
.TintAndShade = 0
.Weight = xlThick
End With
Cells.Select
With Selection.Font
.Name = "Calibri"
.Size = 10
End With
.Columns(1).ColumnWidth = 5
.Columns(2).ColumnWidth = 9
.Columns(3).ColumnWidth = 14
.Range("A7", "H7").Font.Bold = True
Sheets("Header").Range("B1", "B5").Copy .Range("B1")
.Range("B1:H1").HorizontalAlignment = xlCenterAcrossSelection
.Range("B2", "B5").Font.Bold = True
.Range("E2") = "No:"
.Range("F2") = .Range("B8")
.Range("G2") = "To"
.Range("H2") = .Range("B" & lr)
.Range("G3") = "Date"
.Range("H3") = .Range("E8")
.Range("H3").NumberFormat = ("dd/mm/yyyy")
.Range("F2", "H2").NumberFormat = "0000000"
Application.Goto .Range("A1"), scroll:=True
End With
End Sub
Kind regards
Bookmarks