Guest User

Untitled

a guest
Apr 19th, 2018
52
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 29.77 KB | None | 0 0
  1. Option Explicit
  2. Option Compare Text
  3.  
  4. Private Sub Worksheet_Change(ByVal Target As Range)
  5.  
  6. Dim tbl As ListObject
  7. Dim splitVal As Long
  8. Dim colName As String
  9. Dim keyCells As Range, cel As Range, qtySplitRng As Range, chngReasonRng As Range
  10. Dim blckdRng As Range, dateRng As Range, openPOCheck As Range, qtyShippedRng As Range
  11. Dim dict As Object
  12. Dim dontSplit As Boolean: dontSplit = True
  13. Dim wb As Workbook, ws As Worksheet
  14. Dim totShipped As Long, openQty As Long
  15.  
  16. On Error GoTo ErrorHandler
  17.  
  18. 'PW
  19. Set wb = ThisWorkbook
  20. Set ws = wb.Worksheets("Open Orders")
  21. Set dict = CreateObject("Scripting.Dictionary")
  22. Set tbl = ws.ListObjects(1)
  23. Set qtySplitRng = tbl.ListColumns("Qty of shipments").Range
  24. Set chngReasonRng = Union(tbl.ListColumns("Other Reason for Change").Range, tbl.ListColumns("Other Reason for Delay (Prod Lot)").Range, tbl.ListColumns("Other Reason for Delay (Lab dip)").Range)
  25. Set blckdRng = Union(Range("LateDaysRange"), Range("ETARange"), Range("LeadTimeRange"), Range("QueryRange"), tbl.ListColumns("COMMENTS").Range, tbl.ListColumns("CHECK").Range)
  26. Set dateRng = Union(tbl.ListColumns("Submit date").Range, tbl.ListColumns("Submit prod lot date").Range, tbl.ListColumns("Work in progress").Range, tbl.ListColumns("PO Dlvry Date").Range, tbl.ListColumns("NEW PO Dlvry Date").Range)
  27. Set qtyShippedRng = tbl.ListColumns("Real QTY shipped").DataBodyRange
  28.  
  29. dict.Add "Other Reason for Change", "PO Delivery Date"
  30. dict.Add "Other Reason for Delay (Prod Lot)", "Prod Lot Date"
  31. dict.Add "Other Reason for Detail (Lab Dip)", "Lab Dip Date"
  32.  
  33. If Intersect(Target, qtySplitRng) Is Nothing Then
  34. If Intersect(Target, qtyShippedRng) Is Nothing Then
  35. If Intersect(Target, chngReasonRng) Is Nothing Then
  36. If Intersect(Target, blckdRng) Is Nothing Then
  37. If Intersect(Target, dateRng) Is Nothing Then
  38. Exit Sub
  39. Else
  40. WBFast
  41. Call DateCheck(Target)
  42. GoTo ExitHandler
  43. End If
  44. Else
  45. WBFast
  46. Application.Undo
  47. MsgBox "You tried to edit a blocked range.", vbInformation, "Blocked Range"
  48. GoTo ExitHandler
  49. End If
  50. Else
  51. WBFast
  52. For Each cel In Target.Cells
  53. Set keyCells = cel.Offset(, -1)
  54. colName = Cells(1, cel.Column)
  55. Select Case keyCells.Value2
  56. Case "Other"
  57.  
  58. Case Else
  59. cel.ClearContents
  60. MsgBox "You tried to edit a blocked range." & vbNewLine & "Choose a reason for changing " & dict.Item(colName) & " from the dropdown list in " & keyCells.Address & ". If the reason is not there, choose OTHER and then write down your reason here.", vbInformation, "Blocked Range"
  61. GoTo ExitHandler
  62. End Select
  63. Next cel
  64. GoTo ExitHandler
  65. End If
  66. Else
  67. WBFast
  68. totShipped = Application.WorksheetFunction.SumIf(tbl.ListColumns("PO/LINE").DataBodyRange, Target.Offset(0, -42).Value2, tbl.ListColumns("Real QTY shipped").DataBodyRange)
  69. openQty = Target.Offset(0, -32).Value2
  70. totShipped = totShipped - (openQty * 0.15)
  71. If totShipped > openQty Then
  72. Target.ClearContents
  73. MsgBox "You are shipping " & totShipped & " units in total with or without splits out of " & _
  74. openQty & " requested originally in column R. Revise your information is okay please.", vbOKOnly + vbInformation, "Shipping Excess"
  75. End If
  76. GoTo ExitHandler
  77. End If
  78. Else
  79. dontSplit = False
  80. End If
  81.  
  82. If Target.CountLarge > 1 Then GoTo ExitHandler
  83. If (IsNull(Target.Value) Or IsEmpty(Target.Value) Or dontSplit) Then GoTo ExitHandler
  84.  
  85. If IsNumeric(Target.Value) Then
  86. If Target.Value < 2 Then
  87. Target.ClearContents
  88. GoTo ExitHandler
  89. End If
  90. Else
  91. GoTo ExitHandler
  92. End If
  93.  
  94. splitVal = Target.Value2 - 1
  95. Set keyCells = Intersect(Target.EntireRow, tbl.DataBodyRange)
  96. Target.ClearContents
  97.  
  98. Call InsertRows(splitVal, keyCells, ws)
  99.  
  100. On Error GoTo 0
  101.  
  102. ExitHandler:
  103. WBNorm
  104. Exit Sub
  105.  
  106. ErrorHandler:
  107.  
  108. MsgBox "Error " & Err.Number & " (" & Err.Description & ") in procedure Worksheet_Change, line " & Erl & "."
  109. GoTo ExitHandler
  110. End Sub
  111.  
  112. Sub GetDataFromWB()
  113.  
  114.  
  115. Call PW
  116.  
  117. Dim fileName As Variant
  118. Dim oldOPO As Workbook, newOPO As Workbook
  119. Dim oldOPOTable As ListObject, newOPOTable As ListObject
  120. Dim rRows As Long
  121. Dim PO As CPurchaseOrder, dataItems As cItems
  122. Dim OPOInfo As Collection, countPO As Collection
  123. Dim itemKey As String
  124. Dim newWS As Worksheet, oldWS As Worksheet
  125. Dim wbCount As Long
  126. Dim i As Long
  127. Dim keyCells As Range, headerRow As Range
  128. Dim cel As Range
  129. Dim arrPO As Variant, arrNewPO As Variant
  130.  
  131. Dim POLine As Long, LabDipStatus As Long, LabDipDate As Long, ReasonDelayLapDip As Long, OtherReasonDelayLabDip As Long, SubmitLabDip As Long, TrackingLabDip As Long
  132. Dim ProdLotStatus As Long, ProdLotDate As Long, ReasonDelayProdLot As Long, OtherReasonDelayProdLot As Long, SubmitProdLot As Long, TrackingProdLot As Long
  133. Dim ShipFrom As Long, POStatus As Long, WorkProgress As Long, PODeliveryDate As Long, RealQtyShipped As Long
  134. Dim ShipMode As Long, Container As Long, Invoice As Long, ReasonChange As Long, OtherReasonChange As Long, NewPODeliveryDate As Long, Comments As Long
  135.  
  136. Dim StartTime As Double
  137. Dim MinutesElapsed As String
  138.  
  139. 'Remember time when macro starts
  140. StartTime = Timer
  141.  
  142. On Error GoTo ErrorHandler
  143.  
  144. fileName = Application.GetOpenFilename("Excel files (*.xls*), *.xls*", 1, "Select a OPO Workbook")
  145.  
  146. Set newOPO = ThisWorkbook
  147. Set newWS = newOPO.Worksheets("Open Orders")
  148. Set newOPOTable = newWS.ListObjects("TableLawsonQuery")
  149. Set oldOPO = Workbooks.Open(fileName)
  150. Set oldWS = oldOPO.Worksheets("Open Orders")
  151. Set oldOPOTable = oldWS.ListObjects("TableLawsonQuery")
  152. Set headerRow = oldOPOTable.HeaderRowRange
  153.  
  154. Set OPOInfo = New Collection
  155. Set countPO = New Collection
  156.  
  157. WBFast
  158.  
  159.  
  160. POLine = Application.WorksheetFunction.Match("PO/Line", headerRow, 0)
  161. LabDipStatus = Application.WorksheetFunction.Match("Lab dip status", headerRow, 0)
  162. LabDipDate = Application.WorksheetFunction.Match("Submit date", headerRow, 0)
  163. ReasonDelayLapDip = Application.WorksheetFunction.Match("Reason for delay (Lab dip)", headerRow, 0)
  164. OtherReasonDelayLabDip = Application.WorksheetFunction.Match("Other Reason for Delay (Lab dip)", headerRow, 0)
  165. SubmitLabDip = Application.WorksheetFunction.Match("# Submit Lab Dip", headerRow, 0)
  166. TrackingLabDip = Application.WorksheetFunction.Match("Tracking Lab Dip", headerRow, 0)
  167. ProdLotStatus = Application.WorksheetFunction.Match("Prod Lot Status", headerRow, 0)
  168. ProdLotDate = Application.WorksheetFunction.Match("Submit prod lot date", headerRow, 0)
  169. ReasonDelayProdLot = Application.WorksheetFunction.Match("Reason for delay (Prod Lot)", headerRow, 0)
  170. OtherReasonDelayProdLot = Application.WorksheetFunction.Match("Other Reason for Delay (Prod Lot)", headerRow, 0)
  171. SubmitProdLot = Application.WorksheetFunction.Match("# Submit Prod Lot", headerRow, 0)
  172. TrackingProdLot = Application.WorksheetFunction.Match("Tracking Prod Lot", headerRow, 0)
  173. ShipFrom = Application.WorksheetFunction.Match("Ship from", headerRow, 0)
  174. POStatus = Application.WorksheetFunction.Match("PO Status", headerRow, 0)
  175. WorkProgress = Application.WorksheetFunction.Match("Work in progress", headerRow, 0)
  176. PODeliveryDate = Application.WorksheetFunction.Match("PO Dlvry Date", headerRow, 0)
  177. RealQtyShipped = Application.WorksheetFunction.Match("Real QTY shipped", headerRow, 0)
  178. ShipMode = Application.WorksheetFunction.Match("SHIPMODE", headerRow, 0)
  179. Container = Application.WorksheetFunction.Match("ASAP, AWB # or Container #", headerRow, 0)
  180. Invoice = Application.WorksheetFunction.Match("INVOICE #", headerRow, 0)
  181. ReasonChange = Application.WorksheetFunction.Match("REASON FOR CHANGE", headerRow, 0)
  182. OtherReasonChange = Application.WorksheetFunction.Match("Other Reason for Change", headerRow, 0)
  183. NewPODeliveryDate = Application.WorksheetFunction.Match("NEW PO Dlvry Date", headerRow, 0)
  184. Comments = Application.WorksheetFunction.Match("COMMENTS", headerRow, 0)
  185.  
  186. arrPO = oldOPOTable.DataBodyRange.Value2
  187. oldOPO.Close False
  188.  
  189. For rRows = 1 To UBound(arrPO)
  190. If Len(arrPO(1, 64)) > 11 Then
  191. 'Counts duplicate values in old OPO
  192. itemKey = CStr(arrPO(rRows, POLine))
  193.  
  194. Set dataItems = Nothing: On Error Resume Next
  195. Set dataItems = countPO(itemKey): On Error GoTo 0
  196.  
  197. If dataItems Is Nothing Then
  198. Set dataItems = New cItems
  199. dataItems.Key = itemKey
  200. countPO.Add dataItems, itemKey
  201. End If
  202.  
  203. With dataItems
  204. .Count = .Count + 1
  205. End With
  206.  
  207.  
  208. '------OLD OPO INFO------'
  209. On Error Resume Next
  210. Set PO = New CPurchaseOrder
  211. PO.POLine = arrPO(rRows, POLine)
  212.  
  213. PO.LabDipStatus = arrPO(rRows, LabDipStatus)
  214. PO.LabDipDate = arrPO(rRows, LabDipDate)
  215. PO.ReasonDelayLapDip = arrPO(rRows, ReasonDelayLapDip)
  216. PO.OtherReasonDelayLabDip = arrPO(rRows, OtherReasonDelayLabDip)
  217. PO.SubmitLabDip = arrPO(rRows, SubmitLabDip)
  218. PO.TrackingLabDip = arrPO(rRows, TrackingLabDip)
  219.  
  220. PO.ProdLotStatus = arrPO(rRows, ProdLotStatus)
  221. PO.ProdLotDate = arrPO(rRows, ProdLotDate)
  222. PO.ReasonDelayProdLot = arrPO(rRows, ReasonDelayProdLot)
  223. PO.OtherReasonDelayProdLot = arrPO(rRows, OtherReasonDelayProdLot)
  224. PO.SubmitProdLot = arrPO(rRows, SubmitProdLot)
  225. PO.TrackingProdLot = arrPO(1, TrackingProdLot)
  226.  
  227. PO.ShipFrom = arrPO(rRows, ShipFrom)
  228. PO.POrderStatus = arrPO(rRows, POStatus)
  229. PO.WorkProgress = arrPO(rRows, WorkProgress)
  230. PO.PODeliveryDate = arrPO(rRows, PODeliveryDate)
  231. PO.RealQtyShipped = arrPO(rRows, RealQtyShipped)
  232. PO.ShipMode = arrPO(rRows, ShipMode)
  233. PO.Container = arrPO(rRows, Container)
  234. PO.Invoice = arrPO(rRows, Invoice)
  235. PO.ReasonChange = arrPO(rRows, ReasonChange)
  236. PO.OtherReasonChange = arrPO(rRows, OtherReasonChange)
  237. PO.NewPODeliveryDate = arrPO(rRows, NewPODeliveryDate)
  238.  
  239. OPOInfo.Add PO
  240. End If
  241. Next rRows
  242.  
  243. For Each cel In newOPOTable.ListColumns("PO/LINE").DataBodyRange
  244. itemKey = CStr(cel.Value2)
  245. Set dataItems = Nothing: On Error Resume Next
  246. Set dataItems = countPO(itemKey): On Error GoTo 0
  247.  
  248. If dataItems Is Nothing Then
  249.  
  250. Else
  251. If dataItems.Count > 1 Then
  252. Set keyCells = Intersect(cel.EntireRow, newOPOTable.DataBodyRange)
  253. Call InsertRows(dataItems.Count - 1, keyCells, newWS)
  254. countPO.Remove itemKey
  255. End If
  256. End If
  257. Next cel
  258.  
  259. 'Deletes validations because they mess everything up
  260. newWS.Cells.Validation.Delete
  261.  
  262. Set headerRow = Nothing
  263. Set headerRow = newOPOTable.HeaderRowRange
  264.  
  265. POLine = Application.WorksheetFunction.Match("PO/Line", headerRow, 0)
  266. LabDipStatus = Application.WorksheetFunction.Match("Lab dip status", headerRow, 0)
  267. LabDipDate = Application.WorksheetFunction.Match("Submit date", headerRow, 0)
  268. ReasonDelayLapDip = Application.WorksheetFunction.Match("Reason for delay (Lab dip)", headerRow, 0)
  269. OtherReasonDelayLabDip = Application.WorksheetFunction.Match("Other Reason for Delay (Lab dip)", headerRow, 0)
  270. SubmitLabDip = Application.WorksheetFunction.Match("# Submit Lab Dip", headerRow, 0)
  271. TrackingLabDip = Application.WorksheetFunction.Match("Tracking Lab Dip", headerRow, 0)
  272. ProdLotStatus = Application.WorksheetFunction.Match("Prod Lot Status", headerRow, 0)
  273. ProdLotDate = Application.WorksheetFunction.Match("Submit prod lot date", headerRow, 0)
  274. ReasonDelayProdLot = Application.WorksheetFunction.Match("Reason for delay (Prod Lot)", headerRow, 0)
  275. OtherReasonDelayProdLot = Application.WorksheetFunction.Match("Other Reason for Delay (Prod Lot)", headerRow, 0)
  276. SubmitProdLot = Application.WorksheetFunction.Match("# Submit Prod Lot", headerRow, 0)
  277. TrackingProdLot = Application.WorksheetFunction.Match("Tracking Prod Lot", headerRow, 0)
  278. ShipFrom = Application.WorksheetFunction.Match("Ship from", headerRow, 0)
  279. POStatus = Application.WorksheetFunction.Match("PO Status", headerRow, 0)
  280. WorkProgress = Application.WorksheetFunction.Match("Work in progress", headerRow, 0)
  281. PODeliveryDate = Application.WorksheetFunction.Match("PO Dlvry Date", headerRow, 0)
  282. RealQtyShipped = Application.WorksheetFunction.Match("Real QTY shipped", headerRow, 0)
  283. ShipMode = Application.WorksheetFunction.Match("SHIPMODE", headerRow, 0)
  284. Container = Application.WorksheetFunction.Match("ASAP, AWB # or Container #", headerRow, 0)
  285. Invoice = Application.WorksheetFunction.Match("INVOICE #", headerRow, 0)
  286. ReasonChange = Application.WorksheetFunction.Match("REASON FOR CHANGE", headerRow, 0)
  287. OtherReasonChange = Application.WorksheetFunction.Match("Other Reason for Change", headerRow, 0)
  288. NewPODeliveryDate = Application.WorksheetFunction.Match("NEW PO Dlvry Date", headerRow, 0)
  289. Comments = Application.WorksheetFunction.Match("COMMENTS", headerRow, 0)
  290.  
  291. arrNewPOs = newOPOTable.ListColumns(8).Range.Value2
  292.  
  293. For rRows = 2 To UBound(arrNewPOs)
  294. For i = OPOInfo.Count To 1 Step -1
  295. Set PO = OPOInfo(i)
  296. If arrNewPOs(rRows, 1) = PO.POLine Then
  297. newWS.Cells(rRows, LabDipStatus) = PO.LabDipStatus
  298. newWS.Cells(rRows, LabDipDate) = PO.LabDipDate
  299. newWS.Cells(rRows, ReasonDelayLapDip) = PO.ReasonDelayLapDip
  300. newWS.Cells(rRows, OtherReasonDelayLabDip) = PO.OtherReasonDelayLabDip
  301. newWS.Cells(rRows, SubmitLabDip) = PO.SubmitLabDip
  302. newWS.Cells(rRows, TrackingLabDip) = PO.TrackingLabDip
  303.  
  304. newWS.Cells(rRows, ProdLotStatus) = PO.ProdLotStatus
  305. newWS.Cells(rRows, ProdLotDate) = PO.ProdLotDate
  306. newWS.Cells(rRows, ReasonDelayProdLot) = PO.ReasonDelayProdLot
  307. newWS.Cells(rRows, OtherReasonDelayProdLot) = PO.OtherReasonDelayProdLot
  308. newWS.Cells(rRows, SubmitProdLot) = PO.SubmitProdLot
  309. newWS.Cells(rRows, TrackingProdLot) = PO.TrackingProdLot
  310.  
  311. newWS.Cells(rRows, ShipFrom) = PO.ShipFrom
  312. newWS.Cells(rRows, POStatus) = PO.POrderStatus
  313. newWS.Cells(rRows, WorkProgress) = PO.WorkProgress
  314. newWS.Cells(rRows, PODeliveryDate) = PO.PODeliveryDate
  315. newWS.Cells(rRows, RealQtyShipped) = PO.RealQtyShipped
  316. newWS.Cells(rRows, ShipMode) = PO.ShipMode
  317. newWS.Cells(rRows, Container) = PO.Container
  318. newWS.Cells(rRows, Invoice) = PO.Invoice
  319. newWS.Cells(rRows, ReasonChange) = PO.ReasonChange
  320. newWS.Cells(rRows, OtherReasonChange) = PO.OtherReasonChange
  321. newWS.Cells(rRows, NewPODeliveryDate) = PO.NewPODeliveryDate
  322.  
  323. OPOInfo.Remove i
  324. Exit For
  325. End If
  326. Next i
  327. Next rRows
  328.  
  329. Set keyCells = newOPOTable.ListColumns("Lab dip status").DataBodyRange
  330. Call DoValidation("Wrong value", 3, "=INDIRECT(""TableLabProdStatus[LabProdStatus]"")", keyCells, "Choose a value from drop down list")
  331.  
  332. Set keyCells = newOPOTable.ListColumns("Prod Lot Status").DataBodyRange
  333. Call DoValidation("Wrong value", 3, "=INDIRECT(""TableLabProdStatus[LabProdStatus]"")", keyCells, "Choose a value from drop down list")
  334.  
  335. Set keyCells = newOPOTable.ListColumns("Reason for delay (Lab dip)").DataBodyRange
  336. Call DoValidation("Wrong value", 3, "=INDIRECT(""TableLabDipReasons[LabDipReasons]"")", keyCells, "Choose a value from drop down list")
  337.  
  338. Set keyCells = newOPOTable.ListColumns("Reason for delay (Prod Lot)").DataBodyRange
  339. Call DoValidation("Wrong value", 3, "=INDIRECT(""TableProdLotReasons[ProdLotReasons]"")", keyCells, "Choose a value from drop down list")
  340.  
  341. Set keyCells = newOPOTable.ListColumns("PO Status").DataBodyRange
  342. Call DoValidation("Wrong value", 3, "=INDIRECT(""TablePOStatus[POStatus]"")", keyCells, "Choose a value from drop down list")
  343.  
  344. Set keyCells = newOPOTable.ListColumns("Ship from").DataBodyRange
  345. Call DoValidation("Wrong value", 3, "=INDIRECT(""TableShipFrom[ShipFrom]"")", keyCells, "Choose a value from drop down list")
  346.  
  347.  
  348. Set keyCells = newOPOTable.ListColumns("SHIPMODE").DataBodyRange
  349. Call DoValidation("Wrong value", 3, "=INDIRECT(""TableShipMode[ShipMode]"")", keyCells, "Choose a value from drop down list")
  350.  
  351. Set keyCells = newOPOTable.ListColumns("REASON FOR CHANGE").DataBodyRange
  352. Call DoValidation("Wrong value", 3, "=INDIRECT(""TableReasonChange[ReasonChange]"")", keyCells, "Choose a value from drop down list")
  353.  
  354. 'Determine how many seconds code took to run
  355. MinutesElapsed = format((Timer - StartTime) / 86400, "hh:mm:ss")
  356.  
  357. 'Notify user in seconds
  358. MsgBox "This code ran successfully in " & MinutesElapsed & " seconds.", vbInformation, "Imported Data Successfully"
  359.  
  360. ExitHandler:
  361. WBNorm
  362. Exit Sub
  363.  
  364. ErrorHandler:
  365. Select Case Err.Number
  366. Case 9
  367. MsgBox "Column, sheet or table not found. Check names in file have not changed and try again." & vbNewLine & _
  368. "Get_Data module |" & Err.Number & ": " & Err.Description & ".", vbInformation, "Not found"
  369. Case Else
  370. MsgBox "Error " & Err.Number & " (" & Err.Description & ") in procedure Worksheet_Change, line " & Erl & "."
  371. GoTo ExitHandler
  372. End Sub
  373.  
  374. Private pPOLine As String
  375. Private pLabDipStatus As String
  376. Private pLabDipDate As String
  377. Private pReasonDelayLapDip As String
  378. Private pOtherReasonDelayLabDip As String
  379. Private pSubmitLabDip As String
  380. Private pTrackingLabDip As String
  381. Private pProdLotStatus As String
  382. Private pProdLotDate As String
  383. Private pReasonDelayProdLot As String
  384. Private pOtherReasonDelayProdLot As String
  385. Private pSubmitProdLot As String
  386. Private pTrackingProdLot As String
  387. Private pShipFrom As String
  388. Private pOrderShipment As String
  389. Private pPOrderStatus As String
  390. Private pWorkProgress As String
  391. Private pPODeliveryDate As String
  392. Private pRealQtyShipped As Long
  393. Private pShipMode As String
  394. Private pContainer As String
  395. Private pInvoice As String
  396. Private pReasonChange As String
  397. Private pOtherReasonChange As String
  398. Private pNewPODeliveryDate As String
  399. Private pComments As String
  400.  
  401. Public Property Get POLine() As String
  402. POLine = pPOLine
  403. End Property
  404. Public Property Let POLine(Value As String)
  405. pPOLine = Value
  406. End Property
  407. '---------------LAB DIP-------------------
  408. '-----------------------------------------
  409. Public Property Get LabDipStatus() As String
  410. LabDipStatus = pLabDipStatus
  411. End Property
  412. Public Property Let LabDipStatus(Value As String)
  413. pLabDipStatus = Value
  414. End Property
  415. Public Property Get LabDipDate() As String
  416. LabDipDate = pLabDipDate
  417. End Property
  418. Public Property Let LabDipDate(Value As String)
  419. pLabDipDate = Value
  420. End Property
  421. Public Property Get ReasonDelayLapDip() As String
  422. ReasonDelayLapDip = pReasonDelayLapDip
  423. End Property
  424. Public Property Let ReasonDelayLapDip(Value As String)
  425. pReasonDelayLapDip = Value
  426. End Property
  427. Public Property Get OtherReasonDelayLabDip() As String
  428. OtherReasonDelayLabDip = pOtherReasonDelayLabDip
  429. End Property
  430. Public Property Let OtherReasonDelayLabDip(Value As String)
  431. pOtherReasonDelayLabDip = Value
  432. End Property
  433. Public Property Get SubmitLabDip() As String
  434. SubmitLabDip = pSubmitLabDip
  435. End Property
  436. Public Property Let SubmitLabDip(Value As String)
  437. pSubmitLabDip = Value
  438. End Property
  439. Public Property Get TrackingLabDip() As String
  440. TrackingLabDip = pTrackingLabDip
  441. End Property
  442. Public Property Let TrackingLabDip(Value As String)
  443. pTrackingLabDip = Value
  444. End Property
  445. '---------------PROD LOT------------------
  446. '-----------------------------------------
  447. Public Property Get ProdLotStatus() As String
  448. ProdLotStatus = pProdLotStatus
  449. End Property
  450. Public Property Let ProdLotStatus(Value As String)
  451. pProdLotStatus = Value
  452. End Property
  453. Public Property Get ProdLotDate() As String
  454. ProdLotDate = pProdLotDate
  455. End Property
  456. Public Property Let ProdLotDate(Value As String)
  457. pProdLotDate = Value
  458. End Property
  459. Public Property Get ReasonDelayProdLot() As String
  460. ReasonDelayProdLot = pReasonDelayProdLot
  461. End Property
  462. Public Property Let ReasonDelayProdLot(Value As String)
  463. pReasonDelayProdLot = Value
  464. End Property
  465. Public Property Get OtherReasonDelayProdLot() As String
  466. OtherReasonDelayProdLot = pOtherReasonDelayProdLot
  467. End Property
  468. Public Property Let OtherReasonDelayProdLot(Value As String)
  469. pOtherReasonDelayProdLot = Value
  470. End Property
  471. Public Property Get SubmitProdLot() As String
  472. SubmitProdLot = pSubmitProdLot
  473. End Property
  474. Public Property Let SubmitProdLot(Value As String)
  475. pSubmitProdLot = Value
  476. End Property
  477. Public Property Get TrackingProdLot() As String
  478. TrackingProdLot = pTrackingProdLot
  479. End Property
  480. Public Property Let TrackingProdLot(Value As String)
  481. pTrackingProdLot = Value
  482. End Property
  483. '---------------PO STATUS-----------------
  484. '-----------------------------------------
  485. Public Property Get ShipFrom() As String
  486. ShipFrom = pShipFrom
  487. End Property
  488. Public Property Let ShipFrom(Value As String)
  489. pShipFrom = Value
  490. End Property
  491. Public Property Get OrderShipment() As String
  492. OrderShipment = pOrderShipment
  493. End Property
  494. Public Property Let OrderShipment(Value As String)
  495. pOrderShipment = Value
  496. End Property
  497. Public Property Get POrderStatus() As String
  498. POrderStatus = pPOrderStatus
  499. End Property
  500. Public Property Let POrderStatus(Value As String)
  501. If Value = "Shipping" Then Value = "In Progress"
  502. pPOrderStatus = Value
  503. End Property
  504. Public Property Get WorkProgress() As String
  505. WorkProgress = pWorkProgress
  506. End Property
  507. Public Property Let WorkProgress(Value As String)
  508. pWorkProgress = Value
  509. End Property
  510. Public Property Get PODeliveryDate() As String
  511. PODeliveryDate = pPODeliveryDate
  512. End Property
  513. Public Property Let PODeliveryDate(Value As String)
  514. pPODeliveryDate = Value
  515. End Property
  516. Public Property Get RealQtyShipped() As Long
  517. RealQtyShipped = pRealQtyShipped
  518. End Property
  519. Public Property Let RealQtyShipped(Value As Long)
  520. pRealQtyShipped = Value
  521. End Property
  522. Public Property Get ShipMode() As String
  523. ShipMode = pShipMode
  524. End Property
  525. Public Property Let ShipMode(Value As String)
  526. Select Case Value
  527. Case "By Air (any carrier)"
  528. Value = "Air (any carrier)"
  529. Case "By Land"
  530. Value = "Land"
  531. Case "By Sea"
  532. Value = "Sea"
  533. Case "By ASAP"
  534. Value = "Expediting (ASAP)"
  535. Case Else
  536.  
  537. End Select
  538. pShipMode = Value
  539. End Property
  540. Public Property Get Container() As String
  541. Container = pContainer
  542. End Property
  543. Public Property Let Container(Value As String)
  544. pContainer = Value
  545. End Property
  546. Public Property Get Invoice() As String
  547. Invoice = pInvoice
  548. End Property
  549. Public Property Let Invoice(Value As String)
  550. pInvoice = Value
  551. End Property
  552. '---------------DLVRY CHANGE--------------
  553. '-----------------------------------------
  554. Public Property Get ReasonChange() As String
  555. ReasonChange = pReasonChange
  556. End Property
  557. Public Property Let ReasonChange(Value As String)
  558. pReasonChange = Value
  559. End Property
  560. Public Property Get OtherReasonChange() As String
  561. OtherReasonChange = pOtherReasonChange
  562. End Property
  563. Public Property Let OtherReasonChange(Value As String)
  564. pOtherReasonChange = Value
  565. End Property
  566. Public Property Get NewPODeliveryDate() As String
  567. NewPODeliveryDate = pNewPODeliveryDate
  568. End Property
  569. Public Property Let NewPODeliveryDate(Value As String)
  570. pNewPODeliveryDate = Value
  571. End Property
  572.  
  573. Public Property Get Comments() As String
  574. Comments = pComments
  575. End Property
  576. Public Property Let Comments(Value As String)
  577. If Err.Number <> 0 Then Resume Next
  578. pComments = Value
  579. End Property
  580.  
  581. Public Key As String
  582. Public Count As Long
  583. Public ItemList As Collection
  584.  
  585. Private Sub Class_Initialize()
  586. Count = 0
  587. Set ItemList = New Collection
  588. End Sub
  589.  
  590. Sub InsertRows(ByVal splitVal As Integer, ByVal keyCells As Range, ws As Worksheet)
  591.  
  592. PW
  593. WBFast
  594. With keyCells
  595. .Offset(1).Resize(splitVal).EntireRow.Insert
  596. .EntireRow.Copy .Offset(1, 0).Resize(splitVal).EntireRow
  597. End With
  598.  
  599. End Sub
  600.  
  601. Public Sub DoValidation(errorTitle As String, valType As Long, valForm As String, rng As Range, errorMsg As String)
  602.  
  603. With rng.Validation
  604. .Delete
  605. .Add Type:=valType, AlertStyle:=xlValidAlertStop, Operator:= _
  606. xlBetween, Formula1:=valForm
  607. .IgnoreBlank = True
  608. .InCellDropdown = True
  609. .InputTitle = ""
  610. .errorTitle = errorTitle
  611. .InputMessage = ""
  612. .ErrorMessage = errorMsg
  613. .ShowInput = True
  614. .ShowError = True
  615. End With
  616.  
  617. End Sub
  618.  
  619. Sub WBFast()
  620. With ThisWorkbook.Application
  621. .EnableEvents = False
  622. .ScreenUpdating = False
  623. .Calculation = xlCalculationManual
  624. End With
  625.  
  626. End Sub
  627.  
  628. Sub WBNorm()
  629. With ThisWorkbook.Application
  630. .EnableEvents = True
  631. .ScreenUpdating = True
  632. .Calculation = xlCalculationAutomatic
  633. End With
  634. End Sub
  635.  
  636. Private Sub Workbook_BeforeClose(Cancel As Boolean)
  637. Dim tbl As ListObject
  638. Dim checkCol As Range
  639. Dim res As Integer
  640. Dim wb As Workbook
  641.  
  642. Set checkCol = Range("TableLawsonQuery[CHECK]")
  643.  
  644. res = Application.WorksheetFunction.CountIfs(checkCol, "<>In progress", checkCol, "<>RIGHT")
  645.  
  646. If res > 0 Then
  647. Select Case MsgBox("There are " & res & " PO(s) with ambiguous information. They are highlighted in red. For more detail as to what is wrong, " & _
  648. "check the column " & Chr(34) & "BM" & Chr(34) & " in Open Orders sheet." & _
  649. vbNewLine & "Check your information please.", vbInformation + vbYesNo + vbDefaultButton1, "OPO Check")
  650.  
  651. Case vbYes
  652. Cancel = True
  653. End Select
  654. End If
  655.  
  656. End Sub
  657.  
  658. Private Sub Workbook_Open()
  659. Dim tblLawson As ListObject, tblControl As ListObject
  660. Dim checkCol As Range
  661. Dim res As Integer
  662. Dim wb As Workbook
  663. Dim ans As String
  664.  
  665.  
  666. Set wb = ThisWorkbook
  667. Set tblLawson = wb.Worksheets("Open Orders").ListObjects("TableLawsonQuery")
  668. Set tblControl = wb.Worksheets("Vendor").ListObjects("TableControl")
  669. Set checkCol = tblLawson.ListColumns("CHECK").DataBodyRange
  670.  
  671. On Error Resume Next
  672. res = Application.WorksheetFunction.CountIfs(checkCol, "<>In progress", checkCol, "<>RIGHT")
  673.  
  674. If res > 0 Then
  675. MsgBox "There are " & res & " PO(s) with ambiguous information. They are highlighted in red. For more detail as to what is wrong, check the column " & Chr(34) & "BM" & Chr(34) & " in Open Orders sheet", vbInformation, "OPO Check"
  676. On Error Resume Next
  677. wb.Worksheets("Open Orders").Activate
  678. tblLawson.ListColumns("CHECK").DataBodyRange.Select
  679. Else
  680. On Error Resume Next
  681. ans = wb.Application.WorksheetFunction.Index(tblControl.ListColumns("ACTIVATE").DataBodyRange, Application.WorksheetFunction.Match("GUIDELINE", tblControl.ListColumns("CONTROL").DataBodyRange, 0))
  682. If ans = "YES" Then wb.Worksheets("Guideline").Activate
  683. End If
  684.  
  685. End Sub
  686.  
  687. Sub FillData()
  688.  
  689. Dim tblControl As ListObject, tblLawson As ListObject
  690. Dim wb As Workbook
  691. Dim wsVen As Worksheet, wsOPO As Worksheet
  692. Dim cel As Range
  693.  
  694.  
  695. Set wb = ThisWorkbook
  696. Set wsVen = wb.Worksheets("Vendor")
  697. Set wsOPO = wb.Worksheets("Open Orders")
  698.  
  699. Set tblControl = wsVen.ListObjects("TableControl")
  700. Set tblLawson = wsOPO.ListObjects("TableLawsonQuery")
  701.  
  702. WBFast
  703. For Each cel In tblControl.ListColumns("CONTROL").DataBodyRange
  704. Select Case cel.Value2
  705. Case "FILL_SHIPMODE"
  706. If cel.Offset(0, 2).Value2 = "YES" Then tblLawson.ListColumns("SHIPMODE").DataBodyRange.Value2 = cel.Offset(0, 1).Value2
  707. Case "FILL_SHIPFROM"
  708. If cel.Offset(0, 2).Value2 = "YES" Then tblLawson.ListColumns("SHIP FROM").DataBodyRange.Value2 = cel.Offset(0, 1).Value2
  709. Case "REQUESTER"
  710. If cel.Offset(0, 2).Value2 = "YES" Then Call DeleteFilterCriteria(cel.Offset(0, 1).Value2, tblLawson, 5)
  711. Case "COMPANY"
  712. If cel.Offset(0, 2).Value2 = "YES" Then Call DeleteFilterCriteria(cel.Offset(0, 1).Value2, tblLawson, 2)
  713. Case "COMPLETE"
  714. If cel.Offset(0, 2).Value2 = "YES" Then Call DeleteFilterCriteria(cel.Offset(0, 1).Value2, tblLawson, 19)
  715. Case Else
  716.  
  717. End Select
  718. Next cel
  719.  
  720. tblLawson.ListColumns("USER").DataBodyRange.Value2 = UserName
  721.  
  722. WBNorm
  723.  
  724. End Sub
  725.  
  726. Sub DeleteFilterCriteria(xCriteria As String, tblTarget As ListObject, filterColumn As Long)
  727.  
  728. 'Call PW
  729.  
  730. Dim ws As Worksheet
  731. Dim wb As Workbook
  732. Dim rngDel As Range, cel As Range
  733. Dim a As Long
  734.  
  735. Set wb = ThisWorkbook
  736. Set ws = wb.Worksheets("Open Orders")
  737.  
  738. 'ws.Unprotect Password
  739. tblTarget.ShowAutoFilter = False
  740. tblTarget.ShowAutoFilter = True
  741.  
  742. With tblTarget
  743. .Range.AutoFilter Field:=filterColumn, Criteria1:=xCriteria, Operator:=xlFilterValues
  744. On Error Resume Next
  745. Set rngDel = Intersect(.DataBodyRange, .DataBodyRange.SpecialCells(xlCellTypeVisible))
  746. End With
  747.  
  748. If Not rngDel Is Nothing Then
  749. For a = rngDel.Areas.Count To 1 Step -1
  750. rngDel.Areas(a).EntireRow.Delete
  751. Next a
  752. End If
  753.  
  754. tblTarget.ShowAutoFilter = False
  755. tblTarget.ShowAutoFilter = True
  756.  
  757. End Sub
Add Comment
Please, Sign In to add comment