the following is the code which i am using for getting specific data from all the sheets in a workbook. but i want to select some sheets only from which i have to get specific data from the selected sheets in the workbook.
tkf.xlsm | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
A | B | C | D | E | F | G | H | I | |||
61 | |||||||||||
62 | |||||||||||
63 | |||||||||||
64 | |||||||||||
65 | |||||||||||
66 | |||||||||||
67 | |||||||||||
68 | |||||||||||
69 | |||||||||||
70 | |||||||||||
71 | |||||||||||
72 | |||||||||||
73 | |||||||||||
74 | |||||||||||
75 | |||||||||||
14530 to 14583-RMS-TI-880 |
VBA Code:
Dim ws As Worksheet, x As String
Dim i As Long, lastrow As Long, f As Long
Dim z As Long
Application.DisplayAlerts = False
'Application.ScreenUpdating = False
For Each ws In ThisWorkbook.Worksheets
If ws.Name = "Summary" Then
ws.Delete
End If
Next ws
With ThisWorkbook
Set ws = .Sheets.Add(After:=.Sheets(.Sheets.Count))
ws.Name = "Summary"
End With
Dim DestSh As Worksheet
Set DestSh = Worksheets("Summary")
For Each ws In Worksheets
lastrow = DestSh.Cells(Rows.Count, "A").End(xlUp).Row
If ws.Name <> DestSh.Name Then
DestSh.Range("A1").Value = "BOS"
DestSh.Range("C1").Value = "FORTIFIED GR A"
DestSh.Range("D1").Value = "FORTIFIED COMMON"
DestSh.Range("E1").Value = "RAW RICE GR A"
DestSh.Range("F1").Value = "RAW RICE COMMON"
DestSh.Range("G1").Value = "BOILED RICE GRADE A"
DestSh.Range("H1").Value = "BOILED RICE COMMON"
DestSh.Range("I1").Value = "AMOUNT"
'DestSh.Range("J1").Value = "Entry Date"
DestSh.Range("A" & Rows.Count).End(xlUp).Offset(1).Value = ws.Name
If ws.Range("AB12") <> 0 And ws.Range("W12").Value = "FORTIFIED RAW RICE:GR A" Then
DestSh.Range("C" & Rows.Count).End(xlUp).Offset(1).Value = ws.Range("AB12").Value
DestSh.Range("D" & Rows.Count).End(xlUp).Offset(1).Value = ws.Range("AB13").Value
DestSh.Range("E" & Rows.Count).End(xlUp).Offset(1).Value = 0
DestSh.Range("F" & Rows.Count).End(xlUp).Offset(1).Value = ws.Range("AB13").Value
DestSh.Range("G" & Rows.Count).End(xlUp).Offset(1).Value = ws.Range("AB14").Value
DestSh.Range("H" & Rows.Count).End(xlUp).Offset(1).Value = ws.Range("AB15").Value
DestSh.Range("I" & Rows.Count).End(xlUp).Offset(1).Value = ws.Range("AG16").Value
'DestSh.Range("J" & Rows.Count).End(xlUp).Offset(1).Value = ws.Range("B7").Value
DestSh.Range("A1" & ":I" & lastrow + 1).Borders.LineStyle = xlContinuous
End If
If ws.Range("AB13") <> 0 And ws.Range("W13").Value = "FORTIFIED RAW RICE:COMMON" Then
DestSh.Range("C" & Rows.Count).End(xlUp).Offset(1).Value = ws.Range("AB12").Value
DestSh.Range("D" & Rows.Count).End(xlUp).Offset(1).Value = ws.Range("AB13").Value
DestSh.Range("E" & Rows.Count).End(xlUp).Offset(1).Value = 0
DestSh.Range("F" & Rows.Count).End(xlUp).Offset(1).Value = 0
DestSh.Range("G" & Rows.Count).End(xlUp).Offset(1).Value = ws.Range("AB14").Value
DestSh.Range("H" & Rows.Count).End(xlUp).Offset(1).Value = ws.Range("AB15").Value
DestSh.Range("I" & Rows.Count).End(xlUp).Offset(1).Value = ws.Range("AG16").Value
'DestSh.Range("J" & Rows.Count).End(xlUp).Offset(1).Value = ws.Range("B7").Value
DestSh.Range("A1" & ":I" & lastrow + 1).Borders.LineStyle = xlContinuous
End If
If ws.Range("AB12") <> 0 And ws.Range("W12").Value = "RAW RICE:GR A" And ws.Range("AB13") <> 0 And ws.Range("W13").Value = "RAW RICE: COMMON" Then
DestSh.Range("C" & Rows.Count).End(xlUp).Offset(1).Value = 0
DestSh.Range("D" & Rows.Count).End(xlUp).Offset(1).Value = 0
DestSh.Range("E" & Rows.Count).End(xlUp).Offset(1).Value = ws.Range("AB12").Value
DestSh.Range("F" & Rows.Count).End(xlUp).Offset(1).Value = ws.Range("AB13").Value
DestSh.Range("G" & Rows.Count).End(xlUp).Offset(1).Value = ws.Range("AB14").Value
DestSh.Range("H" & Rows.Count).End(xlUp).Offset(1).Value = ws.Range("AB15").Value
DestSh.Range("I" & Rows.Count).End(xlUp).Offset(1).Value = ws.Range("AG16").Value
'DestSh.Range("J" & Rows.Count).End(xlUp).Offset(1).Value = ws.Range("B7").Value
DestSh.Range("A1" & ":I" & lastrow + 1).Borders.LineStyle = xlContinuous
ElseIf ws.Range("AB12") <> 0 And ws.Range("W12").Value = "RAW RICE:GR A" Then
DestSh.Range("C" & Rows.Count).End(xlUp).Offset(1).Value = 0
DestSh.Range("D" & Rows.Count).End(xlUp).Offset(1).Value = 0
DestSh.Range("E" & Rows.Count).End(xlUp).Offset(1).Value = ws.Range("AB12").Value
DestSh.Range("F" & Rows.Count).End(xlUp).Offset(1).Value = ws.Range("AB13").Value
DestSh.Range("G" & Rows.Count).End(xlUp).Offset(1).Value = ws.Range("AB14").Value
DestSh.Range("H" & Rows.Count).End(xlUp).Offset(1).Value = ws.Range("AB15").Value
DestSh.Range("I" & Rows.Count).End(xlUp).Offset(1).Value = ws.Range("AG16").Value
'DestSh.Range("J" & Rows.Count).End(xlUp).Offset(1).Value = ws.Range("B7").Value
DestSh.Range("A1" & ":I" & lastrow + 1).Borders.LineStyle = xlContinuous
ElseIf ws.Range("AA13") <> 0 Then
'ws.Range("W13").Copy DestSh.Range("B" & Rows.Count).End(xlUp).Offset(1)
DestSh.Range("C" & Rows.Count).End(xlUp).Offset(1).Value = 0
DestSh.Range("D" & Rows.Count).End(xlUp).Offset(1).Value = 0
DestSh.Range("E" & Rows.Count).End(xlUp).Offset(1).Value = ws.Range("AB12").Value
DestSh.Range("F" & Rows.Count).End(xlUp).Offset(1).Value = ws.Range("AB13").Value
DestSh.Range("G" & Rows.Count).End(xlUp).Offset(1).Value = ws.Range("AB14").Value
DestSh.Range("H" & Rows.Count).End(xlUp).Offset(1).Value = ws.Range("AB15").Value
DestSh.Range("I" & Rows.Count).End(xlUp).Offset(1).Value = ws.Range("AG16").Value
'DestSh.Range("J" & Rows.Count).End(xlUp).Offset(1).Value = ws.Range("B7").Value
DestSh.Range("A1" & ":I" & lastrow + 1).Borders.LineStyle = xlContinuous
ElseIf ws.Range("AA14") <> 0 Then
'ws.Range("W14").Copy DestSh.Range("B" & Rows.Count).End(xlUp).Offset(1)
DestSh.Range("C" & Rows.Count).End(xlUp).Offset(1).Value = 0
DestSh.Range("D" & Rows.Count).End(xlUp).Offset(1).Value = 0
DestSh.Range("E" & Rows.Count).End(xlUp).Offset(1).Value = ws.Range("AB12").Value
DestSh.Range("F" & Rows.Count).End(xlUp).Offset(1).Value = ws.Range("AB13").Value
DestSh.Range("G" & Rows.Count).End(xlUp).Offset(1).Value = ws.Range("AB14").Value
DestSh.Range("H" & Rows.Count).End(xlUp).Offset(1).Value = ws.Range("AB15").Value
DestSh.Range("I" & Rows.Count).End(xlUp).Offset(1).Value = ws.Range("AG16").Value
'DestSh.Range("J" & Rows.Count).End(xlUp).Offset(1).Value = ws.Range("B7").Value
DestSh.Range("A1" & ":I" & lastrow + 1).Borders.LineStyle = xlContinuous
ElseIf ws.Range("AA15") <> 0 Then
'ws.Range("W15").Copy DestSh.Range("B" & Rows.Count).End(xlUp).Offset(1)
DestSh.Range("C" & Rows.Count).End(xlUp).Offset(1).Value = 0
DestSh.Range("D" & Rows.Count).End(xlUp).Offset(1).Value = 0
DestSh.Range("E" & Rows.Count).End(xlUp).Offset(1).Value = ws.Range("AB12").Value
DestSh.Range("F" & Rows.Count).End(xlUp).Offset(1).Value = ws.Range("AB13").Value
DestSh.Range("G" & Rows.Count).End(xlUp).Offset(1).Value = ws.Range("AB14").Value
DestSh.Range("H" & Rows.Count).End(xlUp).Offset(1).Value = ws.Range("AB15").Value
DestSh.Range("I" & Rows.Count).End(xlUp).Offset(1).Value = ws.Range("AG16").Value
'DestSh.Range("J" & Rows.Count).End(xlUp).Offset(1).Value = ws.Range("B7").Value
DestSh.Range("A1" & ":I" & lastrow + 1).Borders.LineStyle = xlContinuous
End If
End If
DestSh.Range("A1:I1").EntireColumn.AutoFit
Next ws
DestSh.Activate
DestSh.Range("A1:I1").EntireColumn.AutoFit
lastrow = DestSh.Cells(Rows.Count, "A").End(xlUp).Row
DestSh.Range("A1" & ":H" & lastrow).Borders.LineStyle = xlContinuous
DestSh.Range("C" & lastrow + 1).Value = WorksheetFunction.Sum(DestSh.Range("C2" & ":C" & lastrow))
DestSh.Range("D" & lastrow + 1).Value = WorksheetFunction.Sum(DestSh.Range("D2" & ":D" & lastrow))
DestSh.Range("E" & lastrow + 1).Value = WorksheetFunction.Sum(DestSh.Range("E2" & ":E" & lastrow))
DestSh.Range("F" & lastrow + 1).Value = WorksheetFunction.Sum(DestSh.Range("F2" & ":F" & lastrow))
DestSh.Range("G" & lastrow + 1).Value = WorksheetFunction.Sum(DestSh.Range("G2" & ":G" & lastrow))
DestSh.Range("H" & lastrow + 1).Value = WorksheetFunction.Sum(DestSh.Range("H2" & ":H" & lastrow))
DestSh.Range("I" & lastrow + 1).Value = WorksheetFunction.Sum(DestSh.Range("I2" & ":I" & lastrow))
DestSh.Range("I" & lastrow + 1).Value = WorksheetFunction.Sum(DestSh.Range("I2" & ":I" & lastrow))
DestSh.Range("A" & lastrow + 1).Value = "SUMMARY"
DestSh.Range("A1" & ":I" & lastrow + 1).Borders.LineStyle = xlContinuous
DestSh.Range("C2" & ":H" & lastrow + 1).NumberFormat = "0.00.00"
DestSh.Range("I2" & ":I" & lastrow + 1).NumberFormat = "0.00"
lastrow = DestSh.Cells(Rows.Count, "A").End(xlUp).Row
Worksheets("Summary").Range("B" & lastrow).Value = ""
Worksheets("Summary").Range("B" & lastrow + 1 & ":I" & lastrow + 1).Delete Shift:=xlShiftUp
Worksheets("Summary").Range("I" & lastrow).Value = ""
Worksheets("Summary").Range("B:B").EntireColumn.Hidden = True
Worksheets("Summary").Range("M:M").EntireColumn.Hidden = True
Worksheets("Summary").Range("AB:AB").EntireColumn.Hidden = True
z = 1
Dim Part_text As String
Dim Part2_text As String
Dim Part3_text As String
Dim myrange As Range
DestSh.Activate
lastrow = DestSh.Cells(Rows.Count, "A").End(xlUp).Row
Part_text = "RMS"
Set myrange = Worksheets("Summary").Range("A1" & ":A" & lastrow)
For Each cell In myrange
If InStr(UCase(cell.Value), UCase(Part_text)) <> 0 Then
cell.Interior.ColorIndex = 6
For z = 1 To 7
cell.Offset(0, z).Interior.ColorIndex = 6
Next
End If
Next
DestSh.Range("L1").Value = "BOS"
DestSh.Range("N1").Value = "FORTIFIED GR A"
DestSh.Range("O1").Value = "FORTIFIED COMMON"
DestSh.Range("P1").Value = "RAW RICE GR A"
DestSh.Range("Q1").Value = "RAW RICE COMMON"
DestSh.Range("R1").Value = "BOILED RICE GRADE A"
DestSh.Range("S1").Value = "BOILED RICE COMMON"
DestSh.Range("T1").Value = "AMOUNT"
'DestSh.Range("U1").Value = "Entry Date"
For k = 2 To lastrow
Part2_text = Worksheets("Summary").Cells(k, 1).Value
If InStr(1, Part2_text, "KMS", vbTextCompare) > 0 Then
Worksheets("Summary").Range("A" & k).Copy
Worksheets("Summary").Range("L" & k).PasteSpecial
Worksheets("Summary").Range("C" & k).Copy
Worksheets("Summary").Range("N" & k).PasteSpecial
Worksheets("Summary").Range("D" & k).Copy
Worksheets("Summary").Range("O" & k).PasteSpecial
Worksheets("Summary").Range("E" & k).Copy
Worksheets("Summary").Range("P" & k).PasteSpecial
Worksheets("Summary").Range("F" & k).Copy
Worksheets("Summary").Range("Q" & k).PasteSpecial
Worksheets("Summary").Range("G" & k).Copy
Worksheets("Summary").Range("R" & k).PasteSpecial
Worksheets("Summary").Range("H" & k).Copy
Worksheets("Summary").Range("S" & k).PasteSpecial
Worksheets("Summary").Range("I" & k).Copy
Worksheets("Summary").Range("T" & k).PasteSpecial
Worksheets("Summary").Range("J" & k).Copy
Worksheets("Summary").Range("U" & k).PasteSpecial
Worksheets("Summary").Range("K" & k).Copy
Worksheets("Summary").Range("V" & k).PasteSpecial
Else
GoTo nextiteration1
End If
nextiteration1:
Next k
lastrow2 = Worksheets("Summary").Cells(Rows.Count, "L").End(xlUp).Row
DestSh.Range("L1" & ":T" & lastrow + 1).Borders.LineStyle = xlContinuous
Worksheets("Summary").Range("L1:Z1").EntireColumn.AutoFit
DestSh.Range("N" & lastrow2 + 1).Value = WorksheetFunction.Sum(DestSh.Range("N2" & ":N" & lastrow2))
DestSh.Range("O" & lastrow2 + 1).Value = WorksheetFunction.Sum(DestSh.Range("O2" & ":O" & lastrow2))
DestSh.Range("P" & lastrow2 + 1).Value = WorksheetFunction.Sum(DestSh.Range("P2" & ":P" & lastrow2))
DestSh.Range("Q" & lastrow2 + 1).Value = WorksheetFunction.Sum(DestSh.Range("Q2" & ":Q" & lastrow2))
DestSh.Range("R" & lastrow2 + 1).Value = WorksheetFunction.Sum(DestSh.Range("R2" & ":R" & lastrow2))
DestSh.Range("S" & lastrow2 + 1).Value = WorksheetFunction.Sum(DestSh.Range("S2" & ":S" & lastrow2))
DestSh.Range("T" & lastrow2 + 1).Value = WorksheetFunction.Sum(DestSh.Range("T2" & ":T" & lastrow2))
DestSh.Range("L" & lastrow2 + 1).Value = "KHARIFF SUMMARY"
'Worksheets("Summary").Range("L1" & ":T" & lastrow2 + 1).Borders.LineStyle = xlContinuous
DestSh.Range("N2" & ":S" & lastrow2 + 1).NumberFormat = "0.00.00"
DestSh.Range("T2" & ":T" & lastrow2 + 1).NumberFormat = "0.00"
lastrow2 = Worksheets("Summary").Cells(Rows.Count, "L").End(xlUp).Row
For k = 2 To lastrow2 + 1
If Worksheets("Summary").Range("L" & k).Value > 0 Then
GoTo nextiteration2
Else
Worksheets("Summary").Range("L" & k & ":U" & k).Delete Shift:=xlShiftUp
k = k - 1
End If
k = k + 1
nextiteration2:
Next
For k = 2 To lastrow2
If Worksheets("Summary").Range("L" & k) = 0 Then
Worksheets("Summary").Range("L" & k & ":U" & k).Delete Shift:=xlShiftUp
End If
Next k
DestSh.Range("AA1").Value = "BOS"
DestSh.Range("AC1").Value = "FORTIFIED GR A"
DestSh.Range("AD1").Value = "FORTIFIED COMMON"
DestSh.Range("AE1").Value = "RAW RICE GR A"
DestSh.Range("AF1").Value = "RAW RICE COMMON"
DestSh.Range("AG1").Value = "BOILED RICE GRADE A"
DestSh.Range("AH1").Value = "BOILED RICE COMMON"
DestSh.Range("AI1").Value = "AMOUNT"
'DestSh.Range("AJ1").Value = "Entry Date"
For k = 2 To lastrow
Part3_text = Worksheets("Summary").Cells(k, 1).Value
If InStr(1, Part3_text, "RMS", vbTextCompare) > 0 Then
Worksheets("Summary").Range("A" & k).Copy
Worksheets("Summary").Range("AA" & k).PasteSpecial
'Worksheets("Summary").Range("B" & k).Copy
'Worksheets("Summary").Range("AB" & k).PasteSpecial
Worksheets("Summary").Range("C" & k).Copy
Worksheets("Summary").Range("AC" & k).PasteSpecial
Worksheets("Summary").Range("D" & k).Copy
Worksheets("Summary").Range("AD" & k).PasteSpecial
Worksheets("Summary").Range("E" & k).Copy
Worksheets("Summary").Range("AE" & k).PasteSpecial
Worksheets("Summary").Range("F" & k).Copy
Worksheets("Summary").Range("AF" & k).PasteSpecial
Worksheets("Summary").Range("G" & k).Copy
Worksheets("Summary").Range("AG" & k).PasteSpecial
Worksheets("Summary").Range("H" & k).Copy
Worksheets("Summary").Range("AH" & k).PasteSpecial
Worksheets("Summary").Range("I" & k).Copy
Worksheets("Summary").Range("AI" & k).PasteSpecial
Worksheets("Summary").Range("J" & k).Copy
Worksheets("Summary").Range("AJ" & k).PasteSpecial
lastrow3 = DestSh.Cells(Rows.Count, "AA").End(xlUp).Row
DestSh.Range("AA1" & ":AI" & lastrow3 + 1).Borders.LineStyle = xlContinuous
Worksheets("Summary").Range("AA1:AI1").EntireColumn.AutoFit
DestSh.Range("AA1" & ":AI" & lastrow3 + 1).Borders.LineStyle = xlContinuous
DestSh.Range("AC2" & ":AH" & lastrow3 + 1).NumberFormat = "0.00.00"
DestSh.Range("AI2" & ":AI" & lastrow3 + 1).NumberFormat = "0.00"
End If
Next k
lastrow3 = Worksheets("Summary").Cells(Rows.Count, "AA").End(xlUp).Row
For k = 2 To lastrow3 + 1
If Worksheets("Summary").Range("AA" & k).Value > 0 Then
GoTo nextiteration3
ElseIf Worksheets("Summary").Range("AA" & k).Value = 0 Then
Worksheets("Summary").Range("AA" & k & ":AI" & k).Delete Shift:=xlShiftUp
k = k - 1
End If
k = k + 1
nextiteration3:
Next
lastrow3 = Worksheets("Summary").Cells(Rows.Count, "AI").End(xlUp).Row
For k = 2 To lastrow3
If Worksheets("Summary").Range("AI" & k) = 0 Then
Worksheets("Summary").Range("AA" & k & ":AI" & k).Delete Shift:=xlShiftUp
End If
Next k
For k = 2 To lastrow3
If Worksheets("Summary").Range("AI" & k) = 0 Then
Worksheets("Summary").Range("AA" & k & ":AI" & k).Delete Shift:=xlShiftUp
End If
Next k
lastrow3 = Worksheets("Summary").Cells(Rows.Count, "AA").End(xlUp).Row
Worksheets("Summary").Range("B:B").EntireColumn.Hidden = True
Worksheets("Summary").Range("M:M").EntireColumn.Hidden = True
Worksheets("Summary").Range("AB:AB").EntireColumn.Hidden = True
DestSh.Range("AC" & lastrow3 + 1).Value = WorksheetFunction.Sum(DestSh.Range("AC2" & ":AC" & lastrow3))
DestSh.Range("AD" & lastrow3 + 1).Value = WorksheetFunction.Sum(DestSh.Range("AD2" & ":AD" & lastrow3))
DestSh.Range("AE" & lastrow3 + 1).Value = WorksheetFunction.Sum(DestSh.Range("AE2" & ":AE" & lastrow3))
DestSh.Range("AF" & lastrow3 + 1).Value = WorksheetFunction.Sum(DestSh.Range("AF2" & ":AF" & lastrow3))
DestSh.Range("AG" & lastrow3 + 1).Value = WorksheetFunction.Sum(DestSh.Range("AG2" & ":AG" & lastrow3))
DestSh.Range("AH" & lastrow3 + 1).Value = WorksheetFunction.Sum(DestSh.Range("AH2" & ":AH" & lastrow3))
DestSh.Range("AI" & lastrow3 + 1).Value = WorksheetFunction.Sum(DestSh.Range("AI2" & ":AI" & lastrow3))
DestSh.Range("AA" & lastrow3 + 1).Value = "RABI SUMMARY"
DestSh.Range("AC2" & ":AH" & lastrow3 + 1).NumberFormat = "0.00.00"
DestSh.Range("AI2" & ":AI" & lastrow3 + 1).NumberFormat = "0.00"
lastrow3 = DestSh.Cells(Rows.Count, "AA").End(xlUp).Row
For k = 2 To lastrow3 + 1
If Worksheets("Summary").Range("AI" & k) = 0 Then
Worksheets("Summary").Range("AA" & k & ":AI" & k).Delete Shift:=xlShiftUp
End If
Next k
lastrow3 = DestSh.Cells(Rows.Count, "AA").End(xlUp).Row
lastrow3 = DestSh.Cells(Rows.Count, "AA").End(xlUp).Row
Worksheets("Summary").Range("AA1" & ":AI" & lastrow3 + 1).Borders.LineStyle = xlContinuous
DestSh.Range("I" & lastrow).Value = WorksheetFunction.Sum(DestSh.Range("I2" & ":I" & lastrow))
DestSh.Range("A1:AI" & lastrow).WrapText = True
lastrow = DestSh.Cells(Rows.Count, "A").End(xlUp).Row
DestSh.PageSetup.PrintTitleRows = ActiveSheet.Rows(1).Address
DestSh.Range("A1:AI" & lastrow).WrapText = True
With ActiveSheet.PageSetup
.FitToPagesWide = False
.Zoom = 100
.LeftMargin = Application.InchesToPoints(0.75)
.RightMargin = Application.InchesToPoints(0.19)
.BottomMargin = Application.InchesToPoints(0.75)
.TopMargin = Application.InchesToPoints(0.75)
.PaperSize = xlPaperLegal
.Orientation = xlLandscape
End With
Worksheets("Summary").Range("A1:J" & lastrow).Select
ActiveSheet.Range("A1:I" & lastrow).PrintOut Copies:=1, Preview:=True, Collate:=True
ThisWorkbook.Save
DestSh.Range("A1:AH" & lastrow).WrapText = True
lastrow2 = DestSh.Cells(Rows.Count, "L").End(xlUp).Row
DestSh.PageSetup.PrintTitleRows = ActiveSheet.Rows(1).Address
DestSh.Range("L1:T" & lastrow2).WrapText = True
With ActiveSheet.PageSetup
.FitToPagesWide = False
.Zoom = 100
.LeftMargin = Application.InchesToPoints(0.75)
.RightMargin = Application.InchesToPoints(0.19)
.BottomMargin = Application.InchesToPoints(0.75)
.TopMargin = Application.InchesToPoints(0.75)
.PaperSize = xlPaperLegal
.Orientation = xlLandscape
End With
DestSh.Range("L1:T" & lastrow2).Select
ActiveSheet.Range("L1:T" & lastrow2).PrintOut Copies:=1, Preview:=True, Collate:=True
ThisWorkbook.Save
DestSh.Range("A1:AI" & lastrow).WrapText = True
lastrow3 = DestSh.Cells(Rows.Count, "AA").End(xlUp).Row
DestSh.PageSetup.PrintTitleRows = ActiveSheet.Rows(1).Address
DestSh.Range("AA1:AI" & lastrow3).WrapText = True
With ActiveSheet.PageSetup
.FitToPagesWide = False
.Zoom = 100
.LeftMargin = Application.InchesToPoints(0.75)
.RightMargin = Application.InchesToPoints(0.19)
.BottomMargin = Application.InchesToPoints(0.75)
.TopMargin = Application.InchesToPoints(0.75)
.PaperSize = xlPaperLegal
.Orientation = xlLandscape
End With
DestSh.Range("AA1:AI" & lastrow3).Select
ActiveSheet.Range("AA1:AI" & lastrow3).PrintOut Copies:=1, Preview:=True, Collate:=True
ThisWorkbook.Save