当前位置:   article > 正文

vba_cosco_report_vba end(xlup).column

vba end(xlup).column
  1. Sub CostcoR()
  2. Dim DISCCO, DESTNCO, DATECO
  3. For i = 1 To Cells(1, Columns.Count).End(xlToLeft).Column
  4. If Cells(1, i) = "EQT_ACTY_LAST_FREE_NAME" Then
  5. Cells(1, i) = "LAST FREE DAY(LFD)"
  6. ElseIf Cells(1, i) = "DISC_VOY_REF" Then
  7. DISCCO = Cells(1, i).Column
  8. ElseIf Cells(1, i) = "DEST_NAME" Then
  9. DESTNCO = Cells(1, i).Column
  10. ElseIf Cells(1, i) = "DISC_VSL_ARRIVAL_DT" Then
  11. DATECO = Cells(1, i).Column
  12. End If
  13. Next i
  14. Dim dic
  15. Set dic = CreateObject("scripting.dictionary")
  16. For i = 2 To Cells(Rows.Count, DESTNCO).End(xlUp).ROW
  17. dic(Cells(i, DESTNCO).Value) = ""
  18. Next i
  19. DestName = dic.Keys
  20. Dim MyBook1, MyBook2, MyBook3 As Workbook
  21. Set MyBook1 = ActiveWorkbook
  22. Application.ScreenUpdating = False
  23. '处理总表
  24. '处理数据并复制
  25. For j = 0 To dic.Count - 1
  26. n = DestName(j)
  27. MyBook1.Sheets("COSTO_IMP2").Cells(1, DESTNCO).AutoFilter Field:=DESTNCO, Criteria1:=n & "*"
  28. MyBook1.Sheets("COSTO_IMP2").Cells(1, DISCCO).AutoFilter Field:=DISCCO, Criteria1:="*PL"
  29. Workbooks.Add
  30. Set MyBook2 = ActiveWorkbook
  31. MyBook2.SaveAs MyBook1.Path & "\" & "Costco - " & n & " - " & Format(Date, "yyyy-mm-dd") & ".xlsx"
  32. Sheets.Add
  33. Sheets.Add
  34. MyBook1.Sheets("COSTO_IMP2").Cells.Copy MyBook2.Sheets(1).Cells
  35. MyBook2.Sheets(1).Cells(1, DATECO).AutoFilter Field:=DATECO, Criteria1:=">" & Date + 1
  36. MyBook2.Sheets(1).Cells.Copy MyBook2.Sheets(2).Cells
  37. MyBook2.Sheets(1).AutoFilterMode = False
  38. MyBook2.Sheets(1).Cells(1, DATECO).AutoFilter Field:=DATECO, Criteria1:="<=" & Date + 1
  39. MyBook2.Sheets(1).Cells.Copy MyBook2.Sheets(3).Cells
  40. MyBook2.Sheets(1).AutoFilterMode = False
  41. MyBook1.Sheets(1).AutoFilterMode = False
  42. Sheets(1).Cells.ColumnWidth = 30
  43. Sheets(1).Cells.RowHeight = 20
  44. Sheets(1).Cells.EntireColumn.AutoFit
  45. Sheets(2).Cells.ColumnWidth = 30
  46. Sheets(2).Cells.RowHeight = 20
  47. Sheets(2).Cells.EntireColumn.AutoFit
  48. Sheets(3).Cells.ColumnWidth = 30
  49. Sheets(3).Cells.RowHeight = 20
  50. Sheets(3).Cells.EntireColumn.AutoFit
  51. Sheets(1).Name = n
  52. Sheets(2).Name = "Onboard" & " - " & n
  53. Sheets(3).Name = "Discharged" & " - " & n
  54. MyBook2.Save
  55. MyBook2.Close
  56. Next j
  57. Application.ScreenUpdating = True
  58. MsgBox "Done"
  59. End Sub
  60. Sub CostcoRbeifen()
  61. Dim DISCCO, DESTNCO, DATECO
  62. For i = 1 To Cells(1, Columns.Count).End(xlToLeft).Column
  63. If Cells(1, i) = "EQT_ACTY_LAST_FREE_NAME" Then
  64. Cells(1, i) = "LAST FREE DAY(LFD)"
  65. ElseIf Cells(1, i) = "DISC_VOY_REF" Then
  66. DISCCO = Cells(1, i).Column
  67. ElseIf Cells(1, i) = "DEST_NAME" Then
  68. DESTNCO = Cells(1, i).Column
  69. ElseIf Cells(1, i) = "DISC_VSL_ARRIVAL_DT" Then
  70. DATECO = Cells(1, i).Column
  71. End If
  72. Next i
  73. Dim dic
  74. Set dic = CreateObject("scripting.dictionary")
  75. For i = 2 To Cells(Rows.Count, DESTNCO).End(xlUp).ROW
  76. dic(Cells(i, DESTNCO).Value) = ""
  77. Next i
  78. DestName = dic.Keys
  79. For i = 0 To dic.Count - 1
  80. MsgBox DestName(i)
  81. Next i
  82. Dim MyBook1, MyBook2, MyBook3 As Workbook
  83. Set MyBook1 = ActiveWorkbook
  84. With Application.FileDialog(msoFileDialogFilePicker)
  85. .Title = "Select A File"
  86. .InitialFileName = "C:\Users\GSC.BFU\Desktop\bOB"
  87. .AllowMultiSelect = False
  88. .Filters.Clear
  89. .Filters.Add "Text File", "*.txt"
  90. .Filters.Add "EXCEL File", "*.xlsx; *.xls", 1
  91. .Filters.Add "All File", "*.*", 1
  92. If .Show Then
  93. .ButtonName = "Select Me"
  94. Set ipath = .SelectedItems
  95. End If
  96. End With
  97. If IsEmpty(ipath) Then Exit Sub
  98. ipath = ipath(1)
  99. Set MyBook3 = Workbooks.Open(ipath)
  100. MyBook3.Sheets("DISCHARGED").Copy After:=MyBook1.Sheets(1)
  101. MyBook3.Sheets("ONBOARD").Copy After:=MyBook1.Sheets(1)
  102. MyBook3.Close
  103. Application.ScreenUpdating = False
  104. '处理总表
  105. '处理数据并复制
  106. For j = 0 To dic.Count - 1
  107. n = DestName(j)
  108. MyBook1.Sheets("COSTO_IMP2").Cells(1, DESTNCO).AutoFilter Field:=DESTNCO, Criteria1:=n & "*"
  109. MyBook1.Sheets("COSTO_IMP2").Cells(1, DISCCO).AutoFilter Field:=DISCCO, Criteria1:="*PL"
  110. Workbooks.Add
  111. Set MyBook2 = ActiveWorkbook
  112. MyBook2.SaveAs MyBook1.Path & "\" & "Costco - " & n & " - " & Format(Date, "yyyy-mm-dd") & ".xlsx"
  113. Sheets.Add
  114. Sheets.Add
  115. Sheets.Add
  116. MyBook1.Sheets("COSTO_IMP2").Cells.Copy MyBook2.Sheets(1).Cells
  117. MyBook2.Sheets(1).Cells(1, DATECO).AutoFilter Field:=DATECO, Criteria1:=">" & Date + 1
  118. MyBook2.Sheets(1).Cells.Copy MyBook2.Sheets(2).Cells
  119. MyBook2.Sheets(1).AutoFilterMode = False
  120. MyBook2.Sheets(1).Cells(1, DATECO).AutoFilter Field:=DATECO, Criteria1:="<=" & Date + 1
  121. MyBook2.Sheets(1).Cells.Copy MyBook2.Sheets(3).Cells
  122. MyBook2.Sheets(1).AutoFilterMode = False
  123. MyBook1.Sheets(1).AutoFilterMode = False
  124. MyBook1.Sheets("DISCHARGED").Copy MyBook2.Sheets(1)
  125. MyBook1.Sheets("ONBOARD").Copy MyBook2.Sheets(1)
  126. For i = 1 To Sheets("DISCHARGED").Cells(2, Columns.Count).End(xlToLeft).Column
  127. If Sheets(5).Rows(1).Find(Sheets("DISCHARGED").Cells(2, i)) <> "" Then
  128. Sheets(5).Columns(Sheets(5).Rows(1).Find(Sheets("DISCHARGED").Cells(2, i)).Column).Copy Sheets("DISCHARGED").Columns(i)
  129. End If
  130. Next i
  131. For i = 1 To Sheets("ONBOARD").Cells(2, Columns.Count).End(xlToLeft).Column
  132. If Sheets(4).Rows(1).Find(Sheets("ONBOARD").Cells(2, i)) <> "" Then
  133. Sheets(4).Columns(Sheets(4).Rows(1).Find(Sheets("ONBOARD").Cells(2, i)).Column).Copy Sheets("ONBOARD").Columns(i)
  134. End If
  135. Next i
  136. Sheets(1).Cells.ColumnWidth = 30
  137. Sheets(1).Cells.RowHeight = 20
  138. Sheets(1).Cells.EntireColumn.AutoFit
  139. o = Sheets(1).Cells(Rows.Count, 1).End(xlUp).ROW
  140. p = Sheets(1).Cells(1, Columns.Count).End(xlToLeft).Column
  141. Sheets(1).[a1].Resize(o, p).Select
  142. Selection.Borders(xlDiagonalDown).LineStyle = xlNone
  143. Selection.Borders(xlDiagonalUp).LineStyle = xlNone
  144. With Selection.Borders(xlEdgeLeft)
  145. .LineStyle = xlContinuous
  146. .ColorIndex = 0
  147. .TintAndShade = 0
  148. .Weight = xlThin
  149. End With
  150. With Selection.Borders(xlEdgeTop)
  151. .LineStyle = xlContinuous
  152. .ColorIndex = 0
  153. .TintAndShade = 0
  154. .Weight = xlThin
  155. End With
  156. With Selection.Borders(xlEdgeBottom)
  157. .LineStyle = xlContinuous
  158. .ColorIndex = 0
  159. .TintAndShade = 0
  160. .Weight = xlThin
  161. End With
  162. With Selection.Borders(xlEdgeRight)
  163. .LineStyle = xlContinuous
  164. .ColorIndex = 0
  165. .TintAndShade = 0
  166. .Weight = xlThin
  167. End With
  168. With Selection.Borders(xlInsideVertical)
  169. .LineStyle = xlContinuous
  170. .ColorIndex = 0
  171. .TintAndShade = 0
  172. .Weight = xlThin
  173. End With
  174. With Selection.Borders(xlInsideHorizontal)
  175. .LineStyle = xlContinuous
  176. .ColorIndex = 0
  177. .TintAndShade = 0
  178. .Weight = xlThin
  179. End With
  180. Sheets(2).Cells.ColumnWidth = 30
  181. Sheets(2).Cells.RowHeight = 20
  182. Sheets(2).Cells.EntireColumn.AutoFit
  183. Sheets(2).Select
  184. o = Sheets(2).Cells(Rows.Count, 2).End(xlUp).ROW
  185. p = Sheets(2).Cells(1, Columns.Count).End(xlToLeft).Column
  186. Sheets(2).[a1].Resize(o, p).Select
  187. Selection.Borders(xlDiagonalDown).LineStyle = xlNone
  188. Selection.Borders(xlDiagonalUp).LineStyle = xlNone
  189. With Selection.Borders(xlEdgeLeft)
  190. .LineStyle = xlContinuous
  191. .ColorIndex = 0
  192. .TintAndShade = 0
  193. .Weight = xlThin
  194. End With
  195. With Selection.Borders(xlEdgeTop)
  196. .LineStyle = xlContinuous
  197. .ColorIndex = 0
  198. .TintAndShade = 0
  199. .Weight = xlThin
  200. End With
  201. With Selection.Borders(xlEdgeBottom)
  202. .LineStyle = xlContinuous
  203. .ColorIndex = 0
  204. .TintAndShade = 0
  205. .Weight = xlThin
  206. End With
  207. With Selection.Borders(xlEdgeRight)
  208. .LineStyle = xlContinuous
  209. .ColorIndex = 0
  210. .TintAndShade = 0
  211. .Weight = xlThin
  212. End With
  213. With Selection.Borders(xlInsideVertical)
  214. .LineStyle = xlContinuous
  215. .ColorIndex = 0
  216. .TintAndShade = 0
  217. .Weight = xlThin
  218. End With
  219. With Selection.Borders(xlInsideHorizontal)
  220. .LineStyle = xlContinuous
  221. .ColorIndex = 0
  222. .TintAndShade = 0
  223. .Weight = xlThin
  224. End With
  225. Sheets(1).Name = "Onboard Vessel" & " - " & n
  226. Sheets(2).Name = "Discharged" & " - " & n
  227. MyBook2.Save
  228. MyBook2.Close
  229. Next j
  230. Application.ScreenUpdating = True
  231. MsgBox "Done"
  232. End Sub

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/2023面试高手/article/detail/170484
推荐阅读
相关标签
  

闽ICP备14008679号