Advertisement
Guest User

Untitled

a guest
Jun 20th, 2019
101
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.58 KB | None | 0 0
  1. Sub gen()
  2.  
  3. Dim wb_1 As Workbook
  4. Dim wb_templ As Workbook
  5. Dim ws_pivot As Worksheet
  6. Dim ws_files As Worksheet
  7. Dim ws_pasted As Worksheet
  8.  
  9. Dim r, k As Integer
  10. Dim name As String
  11. Dim list() As Variant
  12.  
  13. Set wb_1 = ActiveWorkbook
  14. Set ws_pivot = wb_1.Worksheets("Pivot")
  15. Set ws_files = wb_1.Worksheets("Sheet1")
  16.  
  17. Application.DisplayAlerts = False
  18. Application.AskToUpdateLinks = False
  19. Application.ScreenUpdating = False
  20.  
  21. With ws_files
  22. For r = 1 To .UsedRange.Rows.Count
  23. With .Range("A1")
  24. If name = "" Then
  25. GoTo Start
  26. ElseIf .Offset(r, 0).Value <> name Then
  27. ws_pivot.PivotTables("PivotTable1").PivotFields( _
  28. "[DATA].[NUMBER].[NUMBER]" _
  29. ).VisibleItemsList = list 'This is where I get the error
  30.  
  31. Set wb_templ = Workbooks.Open("C:Users…template.xlsx")
  32. Set ws_pasted= wb_templ.Worksheets("Data")
  33. wb_templ.SaveAs ("C:Users....Final " & name)
  34.  
  35. ws_pivot.Range("A8:P" & ws_pivot.UsedRange.Rows.Count).Copy
  36. ws_pasted.Range("A2").PasteSpecial
  37.  
  38. wb_templ.RefreshAll
  39. wb_templ.Save
  40. wb_templ.Close
  41.  
  42. Start:
  43. name = .Offset(r, 0).Value
  44. ReDim list(.Offset(r, 11).Value)
  45. k = 1
  46. list(k) = "[DATA].[NUMBER].&[" & .Offset(r, 2).Value & "]"
  47. k = k + 1
  48. Else:
  49. list(k) = "[DATA].[NUMBER].&[" & .Offset(r, 2).Value & "]"
  50. k = k + 1
  51. End If
  52. End With
  53. Next r
  54. End With
  55.  
  56. Application.DisplayAlerts = True
  57. Application.AskToUpdateLinks = True
  58. Application.ScreenUpdating = True
  59.  
  60. End Sub
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement