Advertisement
Guest User

Untitled

a guest
Sep 3rd, 2015
57
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.38 KB | None | 0 0
  1. Option Base 1
  2.  
  3. Sub populate_acc_template()
  4. '
  5. ' populate_acc_template Macro
  6. ' Customer: ACC. This template populates the spreadsheet with data from an HRIS sheet.
  7. '
  8.  
  9. ' Start by defining the book to be pulled from and getting the first and last rows
  10. ' of that book.
  11.  
  12. Dim template_book As Workbook
  13. Set template_book = ThisWorkbook
  14. Dim pull_book As Workbook
  15. Set pull_book = Workbooks.Open(Application.ActiveWorkbook.Path & "bookssample_book.xlsx")
  16.  
  17. With ActiveSheet
  18. FirstRow = 2
  19. LastRow = .Cells(.Rows.Count, "A").End(xlUp).Row
  20. End With
  21.  
  22. insert_length = LastRow - FirstRow
  23.  
  24.  
  25. ' Now insert the number of rows that we need in the template.
  26.  
  27. template_book.Sheets("Promotion Calculations").Rows(9 & ":" & 9 + insert_length).Insert Shift:=xlDown
  28.  
  29.  
  30. ' Copy and paste the information from the bulk data.
  31.  
  32. Dim paste_array(1 To 9) As String
  33.  
  34. paste_array(1) = 5
  35. paste_array(2) = 6
  36. paste_array(3) = 4
  37. paste_array(4) = 9
  38. paste_array(5) = 10
  39. paste_array(6) = 3
  40. paste_array(7) = 2
  41. paste_array(8) = 7
  42. paste_array(9) = 8
  43.  
  44. For i = 1 To UBound(paste_array)
  45.  
  46. ' Copy the entire column containing text.
  47. template_book.Sheets("Promotion Calculations").Range(Cells(8, paste_array(i)), Cells(8 + insert_length, paste_array(i))).Value = pull_book.Sheets("Data Sheet").Range(Cells(FirstRow, i), Cells(LastRow, i))
  48. Next i
  49. End Sub
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement