Advertisement
Guest User

Untitled

a guest
May 4th, 2016
36
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.72 KB | None | 0 0
  1. Private Sub cmdAdd_Click()
  2. If TrialVersion Then Exit Sub
  3.  
  4. Dim irow As Long
  5. Dim lastRow As Long
  6. Dim iCol As String
  7. Dim c As Range
  8. Dim ws As Worksheet
  9. Dim value As Long
  10. Dim NewPart As Boolean
  11. Dim ws_warehouse(7) As Worksheet '7 is total warehouse tab you have
  12.  
  13. Set ws = Worksheets("Main")
  14.  
  15. Set ws_warehouse(1) = Worksheets("Elkhart East")
  16. Set ws_warehouse(2) = Worksheets("Tennessee")
  17. Set ws_warehouse(3) = Worksheets("Alabama")
  18. Set ws_warehouse(4) = Worksheets("North Carolina")
  19. Set ws_warehouse(5) = Worksheets("Pennsylvania")
  20. Set ws_warehouse(6) = Worksheets("Texas")
  21. Set ws_warehouse(7) = Worksheets("West Coast")
  22.  
  23. Set c = ws.Range("A7:A1048576").Find(What:=Me.PartTextBox.value, SearchOrder:=xlRows, _
  24. SearchDirection:=xlPrevious, LookIn:=xlValues, LookAt:=xlWhole)
  25. If c Is Nothing Then
  26. 'find first empty row in database
  27. lastRow = ActiveSheet.UsedRange.Row - 1 + ActiveSheet.UsedRange.Rows.Count
  28. irow = lastRow + 1
  29. NewPart = True
  30. Else
  31. 'find row where the part is
  32. irow = ws.Cells.Find(What:=Me.PartTextBox.value, SearchOrder:=xlRows, _
  33. SearchDirection:=xlPrevious, LookIn:=xlValues).Row
  34. NewPart = False
  35. End If
  36.  
  37. 'check for a part number
  38. If Trim(Me.PartTextBox.value) = "" Then
  39. Me.PartTextBox.SetFocus
  40. MsgBox "Please Enter A Part Number"
  41. Exit Sub
  42. End If
  43.  
  44. If Trim(Me.MonthComboBox.value) = "" Then
  45. Me.MonthComboBox.SetFocus
  46. MsgBox "Please Enter A Month"
  47. Exit Sub
  48. End If
  49.  
  50. If Trim(Me.AddTextBox.value) = "" Then
  51. Me.AddTextBox.SetFocus
  52. MsgBox "Please Enter A Value To Add Or Substract"
  53. Exit Sub
  54. End If
  55.  
  56. Select Case MonthComboBox.value
  57. Case "Current Month"
  58. iCol = "C"
  59.  
  60. Case "Current Month +1"
  61. iCol = "N"
  62.  
  63. Case "Current Month +2"
  64. iCol = "O"
  65.  
  66. Case "Current Month +3"
  67. iCol = "P"
  68.  
  69. Case "Current Month +4"
  70. iCol = "Q"
  71. End Select
  72.  
  73. actWarehouse = Me.warehousecombobox.ListIndex + 1
  74.  
  75. With ws
  76. .Cells(irow, "A").value = Me.PartTextBox.value
  77. .Cells(irow, iCol).value = .Cells(irow, iCol).value + CLng(Me.AddTextBox.value)
  78. End With
  79.  
  80. With ws_warehouse(actWarehouse)
  81. 'find part number
  82. l_row = .Range("A" & .Rows.Count).End(xlUp).Row
  83.  
  84. NewPart = True
  85. For r = 7 To l_row
  86. If Trim(.Range("A" & r)) = "" Then Exit For
  87. If LCase(.Range("A" & r)) = LCase(Me.PartTextBox.Text) Then
  88. irow = r
  89. Exit For
  90. NewPart = False
  91. End If
  92. Next r
  93. If NewPart Then irow = r
  94.  
  95. .Cells(irow, "A").value = Me.PartTextBox.value
  96. .Cells(irow, iCol).value = .Cells(irow, iCol).value + CLng(Me.AddTextBox.value)
  97. End With
  98.  
  99. 'clear the data
  100. Me.PartTextBox.value = ""
  101. Me.MonthComboBox.value = ""
  102. Me.AddTextBox.value = ""
  103. Me.PartTextBox.SetFocus
  104. Me.warehousecombobox.value = ""
  105.  
  106. End Sub
  107.  
  108. Private Sub cmdClose_Click()
  109. Unload Me
  110. End Sub
  111.  
  112. Private Sub UserForm_Initialize()
  113.  
  114. 'Empty NameTextBox
  115. PartTextBox.value = ""
  116.  
  117. 'Empty PhoneTextBox
  118. AddTextBox.value = ""
  119.  
  120. 'Empty DinnerComboBox
  121.  
  122. 'Fill DinnerComboBox
  123. With MonthComboBox
  124. .AddItem "Current Month"
  125. .AddItem "Current Month +1"
  126. .AddItem "Current Month +2"
  127. .AddItem "Current Month +3"
  128. .AddItem "Current Month +4"
  129.  
  130. End With
  131.  
  132. With warehousecombobox
  133. .AddItem "Elkhart East"
  134. .AddItem "Tennessee"
  135. .AddItem "Alabama"
  136. .AddItem "North Carolina"
  137. .AddItem "Pennsylvania"
  138. .AddItem "Texas"
  139. .AddItem "West Coast"
  140. End With
  141.  
  142. End Sub
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement