gmr4evr1 - Thank you for that code, it worked! this solved request #1.
mgs73 - that didn't seem to work. As far as the alphabetical order of the sheets being saved, I realized it's because of the sorting that I have, I only intended it to do so on the sheets that are created. I'm attempting to include this after the Next ws portion but I'm getting an error (Compile Error: Next without For). Please see below. How can I properly move the highlighted yellow code?
Sub Invoice()
Dim Firstrow As Long
Dim Lastrow As Long
Dim Lrow As Long
With Sheets("Sheet1")
.Select
End With
Firstrow = 2
Lastrow = Cells(Rows.Count, "K").End(xlUp).Row
For Lrow = Lastrow To Firstrow Step -1
With Cells(Lrow, "K")
If Not IsError(.Value) Then
If .Value = 0 Then .EntireRow.Delete
End If
End With
Next Lrow
Dim ws As Worksheet, a, e, dic As Object
Cells.Select
With Selection.Font
.Name = "Arial Narrow"
.Size = 10
Rows("1:10000").RowHeight = 15
Columns("K:L").Select
Selection.Style = "Comma"
End With
Next ws
ActiveSheet.Range("a1:W1").Copy
On Error Resume Next
Application.ScreenUpdating = False
For Each ws In Worksheets
ws.Columns("A:W").Sort Key1:=ws.Columns("J"), Order1:=xlDescending, Key2:=ws.Columns("O"), Order2:=xlAscending
ActiveSheet.Range("A1").PasteSpecial Paste:=xlPasteAll
Application.ScreenUpdating = True
Application.ScreenUpdating = False
Set dic = CreateObject("Scripting.Dictionary")
With Sheets("sheet1").Cells(1).CurrentRegion
.Parent.AutoFilterMode = False
a = .Columns(1).Offset(1).Resize(.Rows.Count - 1).Value
For Each e In a
If Not dic.exists(e) Then
dic(e) = Empty
If Not Evaluate("isref('" & e & "'!a1)") Then
Sheets.Add(after:=Worksheets(Worksheets.Count)).Name = e
End If
Sheets(e).Cells.Clear
.AutoFilter 1, e
.Copy Sheets(e).Cells(1)
With Sheets(e).Cells(1).CurrentRegion
.Subtotal GroupBy:=10, Function:=xlSum, TotalList:=Array(11, 12)
.Parent.Cells.ClearOutline
.Columns.AutoFit
.PageSetup.PrintTitleRows = "$1:$1"
If .Rows.Count > 75 Then
For i = 76 To .Rows.Count Step 75
.Parent.HPageBreaks.Add before:=.Rows(i)
Next
End If
With .Parent.PageSetup
.Orientation = xlLandscape
.FitToPagesWide = 1 '? ---- changed
.Zoom = False
End With
.AutoFilter
End With
Application.ScreenUpdating = True
End If
Next
End With
End Sub
Bookmarks