Guest User

Untitled

a guest
Jun 20th, 2018
60
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.14 KB | None | 0 0
  1. Public Sub Summary_calculation()
  2.  
  3. Dim wb As Workbook
  4. Dim ws As Worksheet
  5. Dim endrow As Integer
  6. Dim temprow As Integer
  7. Dim tempcol As Integer
  8. Dim i As Integer
  9. Dim totalrec As Integer
  10. Dim tmpSheet As Worksheet
  11. Dim SKUCol As Integer
  12. Dim SKUName As String
  13. Dim tmpSheetrow As Integer
  14. Dim tmpcol As Integer
  15. Dim tmpQty As Double
  16.  
  17. Set wb = ActiveWorkbook
  18. Set ws = wb.Sheets("Summary")
  19.  
  20. SKUCol = 3
  21.  
  22. totalrec = ws.Cells(startrow, 1).CurrentRegion.Rows.Count - 1
  23.  
  24. For i = 1 To totalrec
  25.  
  26. SKUName = ws.Cells(i + startrow, SKUCol).Value
  27.  
  28. Set tmpSheet = wb.Sheets(SKUName)
  29.  
  30. 'tmpSheet.Activate (Got 1004 error whenever remove this line of code)
  31.  
  32. tmpSheetrow = tmpSheet.Cells(startrow, Gapcol).CurrentRegion.Rows.Count + startrow - 1
  33.  
  34. For tmpcol = 0 To 16
  35. With wb.Sheets(SKUName)
  36.  
  37. ws.Cells(i + startrow, tmpcol + 4).Value = Application.WorksheetFunction.Sum(.Range(Cells(startrow + 1, PropStartcol + tmpcol), Cells(tmpSheetrow, PropStartcol + tmpcol)))
  38.  
  39. End With
  40. Next tmpcol
  41. ws.Cells(1, 10) = Format(i / totalrec, "00%")
  42. DoEvents
  43. Next i
  44.  
  45. End Sub
Add Comment
Please, Sign In to add comment