Advertisement
YasserKhalil2019

T4093_Export To One Sheet All Names Block

Oct 13th, 2019
132
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.83 KB | None | 0 0
  1. https://excel-egy.com/forum/t4093
  2. ---------------------------------
  3.  
  4. Sub Export_To_One_Sheet_All_Names_Block()
  5. Dim ws As Worksheet, sh As Worksheet, wsResult As Worksheet, b As Boolean, lr As Long, m As Long, r As Long
  6.  
  7. Const sName As String = "Results"
  8. Const lRows As Long = 38
  9.  
  10. Application.ScreenUpdating = False
  11. Set ws = ThisWorkbook.Worksheets("Sheet1")
  12. Set sh = ThisWorkbook.Worksheets("Template")
  13. lr = ws.Cells(Rows.Count, 1).End(xlUp).Row
  14. m = 2: r = 1
  15.  
  16. Application.DisplayAlerts = False
  17. If Evaluate("ISREF('" & sName & "'!A1)") Then ThisWorkbook.Worksheets(sName).Delete
  18. Application.DisplayAlerts = True
  19.  
  20. Set wsResult = ThisWorkbook.Sheets.Add(After:=ThisWorkbook.Sheets(ThisWorkbook.Sheets.Count))
  21.  
  22. Do Until m >= lr
  23. With wsResult
  24. .Name = sName
  25. .DisplayRightToLeft = True
  26. sh.Rows("1:" & lRows).Copy .Rows(r)
  27. If b = False Then sh.Range("A" & r & ":G" & r + lRows - 1).Copy: .Range("A" & r).PasteSpecial Paste:=xlPasteColumnWidths: b = True
  28. .Range("D" & r + 12).Resize(16, 2).Value = ws.Range("A" & m).Resize(16, 2).Value
  29. .HPageBreaks.Add Before:=.Cells(r + lRows, 1)
  30.  
  31. Application.PrintCommunication = False
  32. With .PageSetup
  33. .RightHeader = "&""Arial,Bold""&12&P"
  34. .Orientation = xlPortrait
  35. .FitToPagesWide = 1
  36. .FitToPagesTall = False
  37. End With
  38. Application.PrintCommunication = True
  39. End With
  40. m = m + 16: r = r + lRows
  41. Loop
  42. Application.ScreenUpdating = True
  43. End Sub
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement