Advertisement
Guest User

Untitled

a guest
Jun 14th, 2019
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. Sub LeasePriceModel_Button2_Click()
  2.  
  3. currentWs = 15
  4. currentItem = 16
  5. lpmItem = 16
  6. standardSheetNumber = 15
  7. mySheets = Worksheets.Count
  8. firstProduct = 0
  9. lastProduct = 14
  10. StandardRowsPCList = 15
  11. StandardRowsInSheet = 15
  12. equipmentSheet = 2
  13. productListEnd = Sheets(2).Range("E16").End(xlDown).Row - StandardRowsPCList
  14. itemsInSheet = 0
  15. filledItems = 0
  16.  
  17. For i = standardSheetNumber To mySheets
  18.    
  19.     Sheets(currentWs).Activate
  20.     itemsInSheet = Sheets(currentWs).Range("A16").End(xlDown).Row - StandardRowsInSheet
  21.    
  22.     For j = 0 To productListEnd - 1
  23.    
  24.         ProductCode = Sheets(equipmentSheet).Cells(currentItem + j, 5).Value
  25.         productQty = Sheets(equipmentSheet).Cells(currentItem + j, 1).Value
  26.         productCost = Sheets(equipmentSheet).Cells(currentItem + j, 10).Value
  27.        
  28.         For k = firstProduct To itemsInSheet
  29.             If Sheets(currentWs).Cells(currentItem + k, 4).Value <> 1 Then
  30.                 pcToCheck = Sheets(currentWs).Cells(currentItem + k, 1).Value
  31.  
  32.                 If pcToCheck = ProductCode Then
  33.                     Sheets(currentWs).Cells(currentItem + k, 6).Value = productCost
  34.                     Sheets(currentWs).Cells(currentItem + k, 4).Value = Sheets(currentWs).Cells(currentItem + k, 4).Value + 1
  35.                     Exit For
  36.                 End If
  37.            
  38.             End If
  39.         Next k
  40.        
  41.         filledItems = WorksheetFunction.Sum(Sheets(currentWs).Range(Cells(16, 4), Cells(16 + itemsInSheet, 4)))
  42.        
  43.         If filledItems = itemsInSheet Then
  44.             totalPrice = WorksheetFunction.Sum(Sheets(currentWs).Range(Cells(16, 6), Cells(16 + itemsInSheet, 6)))
  45.             Sheets(6).Cells(lpmItem, 15).Value = totalPrice
  46.             lpmItem = lpmItem + 2
  47.             Exit For
  48.         End If
  49.  
  50.     Next j
  51.    
  52.     If currentWs < mySheets Then
  53.         currentWs = currentWs + 1
  54.     Else
  55.         Sheets(6).Activate
  56.     End If
  57.  
  58. Next i
  59.  
  60.  
  61. End Sub
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement