Advertisement
Guest User

Untitled

a guest
May 13th, 2016
136
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.27 KB | None | 0 0
  1. Sub Exercise() ' ' to read data from file tasks.xls and
  2. Dim Arr As Variant, Arr1 As Variant ' feed the task name for the person
  3. Dim iRow As Integer ' in a month in this file
  4. Dim iCol As Integer
  5. Dim i As Integer, x As Integer
  6. Dim name As String
  7.  
  8. 'name = Cells(1, 1).Value
  9. Arr = Workbooks.Open("E:tasks.xlsx").Sheets("Sheet1").Range("B1:E1").Value
  10. Arr1 = Workbooks.Open("E:tasks.xlsx").Sheets("Sheet1").Range("B2:E2").Value
  11. Sheets(1).Cells(1, 1).Select ' go to beginning cell
  12.  
  13. For i = 1 To Arr1(1, 1)
  14. Cells(6, 4 + i).Value = Arr(1, 1)
  15. a = i + 4
  16. Next i
  17.  
  18.  
  19. For i = 1 To Arr1(1, 2)
  20. Cells(6, a + i).Value = Arr(1, 2)
  21. b = a + i
  22. Next i
  23.  
  24. For i = 1 To Arr1(1, 3)
  25. Cells(6, b + i).Value = Arr(1, 3)
  26. C = b + i
  27. Next i
  28.  
  29. For i = 1 To Arr1(1, 4)
  30. Cells(6, C + i).Value = Arr(1, 4)
  31. d = a + i
  32. Next i
  33.  
  34. Do While ActiveCell.Row <> Sheets(1).Range("A" & Rows.Count).End(xlUp).Row
  35. ' some times i get infinte loop
  36. ActiveCell.Offset(2, 0).Select ' span till the last
  37. name = ActiveCell.Value ' non empty row
  38. Arr = Sheets(1).Range(ActiveCell.Offset(0, 1), ActiveCell.Offset(0, 5)).Value
  39. Arr1 = Sheets(1).Range(ActiveCell.Offset(1, 1), ActiveCell.Offset(1, 5)).Value
  40.  
  41.  
  42. With ThisWorkbook.Sheets(3) 'algorithm to search the name ' positon in this excel file
  43. Dim findrow As Range
  44. Set findrow = .Range("A:A").Find(What:=name, LookIn:=xlValues)
  45. iRow = findrow.Row ' required row where name is found
  46.  
  47. For i = 1 To Arr1(1, 1)
  48. Cells(iRow, 4 + i).Value = Arr(1, 1)
  49. a = i + 4
  50. Next i
  51.  
  52. For i = 1 To Arr1(1, 2)
  53. Cells(iRow, a + i).Value = Arr(1, 2)
  54. b = a + i
  55. Next i
  56.  
  57. For i = 1 To Arr1(1, 3)
  58. Cells(iRow, b + i).Value = Arr(1, 3)
  59. C = b + i
  60. Next i
  61.  
  62. For i = 1 To Arr1(1, 4)
  63. Cells(iRow, C + i).Value = Arr(1, 4)
  64. d = a + i
  65. Next i
  66.  
  67. Loop
  68.  
  69. End Sub
  70.  
  71. End with
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement