- ©«¤l
- 5923
- ¥DÃD
- 13
- ºëµØ
- 1
- ¿n¤À
- 5986
- ÂI¦W
- 0
- §@·~¨t²Î
- win10
- ³nÅ骩¥»
- Office 2010
- ¾\ŪÅv
- 150
- ©Ê§O
- ¨k
- ¨Ó¦Û
- ¥xÆW°ò¶©
- µù¥U®É¶¡
- 2010-5-1
- ³Ì«áµn¿ý
- 2022-1-23
|
¥»©«³Ì«á¥Ñ GBKEE ©ó 2017-7-27 07:45 ½s¿è
¦^´_ 11# PJChen
«·s¦^¨ì 11# ªº°ÝÃD
°ÝÃD½ÆÂø¥i¥H¤@Ó¤@Ó¨Ó
**********************************
q³æ©ú²Óªíªº®Mªí¼Ò¦¡¬°¡G
1. ¥HVBA³øªí«ü¥O.xlsm H2¬°·Ç«h,·j´Mq³æ©ú²ÓªíªºB2Äæ¦ì,·í²Å¦XH2®É(¥Ø«eªºÈ¬OMSO17060001)
2. ¥Ø«e²Å¦XªºÀx¦s®æ¬OB11,«hcopy B11~BAªº¸ê®Æ³Ì©³ºÝ,¦pªG§ä¤£¨ì¥Nªí¨S¦³¸ê®Æ¥i½Æ»s.
3. ¶K¤W¸ê®Æ¦Ü¥ØªºÀÉ Q:\00_¬ì¼Ý\¥X³f¤å¥ó³sµ²\ERP_Data.xlsxªº"q³æ.sheet",²Å¦XBÄæMSO17060001ªº¦ì¸m,¨Ãª½±µÂл\ì¸ê®Æ,¿ï¾Ü©Ê¶K¤WÈ(¤£n§ó§ïì¸ê®Æªº®æ¦¡),¦pªG§ä¤£¨ì®É,´N·í¦¨¬O³Ì·sªº¸ê®Æ,ª½±µ±q¥ØªºÀɪºBÄæ³Ì©³ºÝ¤U¤@Ä檺ªÅ¥Õ¦C¶K¤W(©Ò¥Hn¯à¦Û°Ê°»´ú¸ê®Æªº³Ì¥½ºÝ,¦pªG¦³¥þ¦CªÅ¥Õ(«D¥þ¦CªÅ¥Õ¤£ºâ¬OªÅ¥Õ),¨äªÅ¥Õªº²Ä¤@¦C(Y¦³ªÅ¥Õ¦C«á¦A¥X²{ªº¸ê®Æµø¦PªÅ¥Õ)§Y¬O¶K·s¸ê®Æªº¦a¤è.
********************************- Option Explicit
- Dim ¥ØªºÀÉ As Workbook, ¨Ó·½ÀÉ As Workbook
- Dim ·Ç«h³æ¸¹ As String, ·Ç«h³æ¸¹_Rng As Range
- Dim Äæ¦ì As String, ¤u§@¶ As String, Msg As String
- Sub Main()
- Dim Table As Range, Sh As Worksheet, i As Integer
- Msg = ""
- With ThisWorkbook.Sheets("VBA«ü¥O") '³]©w·Ç«h½d³ò
- Set Table = .Range("G2", .Range("G2").End(xlDown)).Resize(, 2) '
- End With
- File_settings ¥ØªºÀÉ, "ERP_Data.XLSX" '³]©w¥ØªºÀÉ
- For i = 1 To Table.Rows.Count
- File_settings ¨Ó·½ÀÉ, Table.Cells(i, 1) & ".XLSX" '³]©w¨Ó·½ÀÉ
- ·Ç«h³æ¸¹ = Table.Cells(i, 2) 'Ū¨ú·Ç«h
- ¤u§@¶ = Mid(Table.Cells(i, 1), 1, 2) '¥ØªºÀɪº¤u§@ªí¦WºÙ
- Äæ¦ì = IIf(¤u§@¶ = "q³æ" Or ¤u§@¶ = "¶i³f" Or ¤u§@¶ = "»â®Æ", "C:C", "B:B") '¥ØªºÀɪº¤u§@ªíªºÄæ¦ì
- xSearch
- ¨Ó·½ÀÉ.Close False
- Next
- '******************************
- '¥ØªºÀÉ.Close True ¼È®É¤£¦sÀÉ
- '******************************
- If Msg <> "" Then MsgBox Msg
- End Sub
- Private Sub xSearch()
- Dim D As Object, M, ¤u§@¶ As String
- Set D = CreateObject("SCRIPTING.DICTIONARY") '¦r¨åª«¥ó
- With ¨Ó·½ÀÉ.Sheets(1) '.Range("b:b") '¨Ó·½ÀɲĤ@Ó¤u§@ªíªºBÄæ
- .Cells.Sort .Range("B1"), 1, Header:=xlYes '±Æ§Ç
- M = Application.Match(·Ç«h³æ¸¹, .Range("b:b").Cells, 0)
- '**********************************
- If IsError(M) Then Exit Sub '¨Ó·½ÀɨS¦³§ä¨ì·Ç«h,Â÷¶}³oµ{¦¡ (¤£³B²z)
- '**§ä¨ì·Ç«h,³]©w·Ç«hªº¸ê®Æ½d³ò
- With .Range("b:b")
- Do While .Cells(M) = ·Ç«h³æ¸¹
- '.Range("B" & M & ":BA" & M) -> ¦@27Äæ
- If TypeName(D(.Cells(M).Value)) <> "Range" Then
- Set D(·Ç«h³æ¸¹) = .Range("a" & M).Resize(, 27)
- Else
- Set D(·Ç«h³æ¸¹) = Union(D(·Ç«h³æ¸¹), .Range("a" & M).Resize(, 27))
- End If
- M = M + 1
- Loop
- End With
- Set ·Ç«h³æ¸¹_Rng = D(·Ç«h³æ¸¹)
- End With
- ¥ØªºÀÉ_·Ç«h³æ¸¹
- End Sub
- Private Sub ¥ØªºÀÉ_·Ç«h³æ¸¹()
- Dim M As Variant, D As Object, xRng As Range, i As Integer, ¤u§@¶³æ¸¹_Rng As Range
-
- With ¥ØªºÀÉ.Sheets(¤u§@¶)
- '¥ØªºÀɪº¤u§@¶¦³µL·Ç«h³æ¸¹
- M = Application.Match(·Ç«h³æ¸¹, .Range(Äæ¦ì), 0)
- '**************************
- If IsError(M) Then 'µL·Ç«h³æ¸¹
- M = Split(.UsedRange.Address, "$")
- M = M(UBound(M)) '¤u§@¶³Ì©³ºÝªº¦C
- Do While Application.CountA(.Rows(M)) > 1 '¥²»Ý¨S¦³¸ê®Æ
- M = M + 1
- Loop
- '*********************************
- Set ¤u§@¶³æ¸¹_Rng = .Range(Äæ¦ì).Cells(M).Resize(·Ç«h³æ¸¹_Rng.Rows.Count, ·Ç«h³æ¸¹_Rng.Columns.Count)
- Msg = Msg & vbLf & ¤u§@¶ & " ¥[¤J: " & ·Ç«h³æ¸¹
- Else ''¦³·Ç«h³æ¸¹
- Set D = CreateObject("SCRIPTING.DICTIONARY")
- .Cells.Sort .Range(Äæ¦ì).Cells(1), 1, Header:=xlYes '¥ý±Æ§Ç
- With .Range(Äæ¦ì)
- M = Application.Match(·Ç«h³æ¸¹, .Cells, 0) '´M§ä³æ¸¹¦C¸¹
- '³]©w ¤u§@¶·Ç«h³æ¸¹ªº½d³ò*********
- Do While .Cells(M) = ·Ç«h³æ¸¹
- If TypeName(D(.Cells(M).Value)) <> "Range" Then
- Set D(·Ç«h³æ¸¹) = .Range("a" & M).Resize(, 27)
- Else
- Set D(·Ç«h³æ¸¹) = Union(D(·Ç«h³æ¸¹), .Range("a" & M).Resize(, 27))
- End If
- M = M + 1
- Loop
- End With
- With D(·Ç«h³æ¸¹)
- If .Rows.Count > ·Ç«h³æ¸¹_Rng.Rows.Count Then '¤u§@¶³æ¸¹¦C¼Æ>·Ç«h³æ¸¹¦C¼Æ
- For i = .Rows.Count To ·Ç«h³æ¸¹_Rng.Rows.Count + 1 Step -1
- Rows(i).EntireRow.Delete '¾ã¦C§R°£
- Next
- ElseIf .Rows.Count < ·Ç«h³æ¸¹_Rng.Rows.Count Then '¤u§@¶³æ¸¹¦C¼Æ<·Ç«h³æ¸¹¦C¼Æ
- For i = .Rows.Count + 1 To ·Ç«h³æ¸¹_Rng.Rows.Count
- Rows(i + 1).EntireRow.Insert '·s¼W¤@¦C
- Next
- End If
- End With
- Set ¤u§@¶³æ¸¹_Rng = D(·Ç«h³æ¸¹).Resize(D(·Ç«h³æ¸¹).Rows.Count)
- Msg = Msg & vbLf & ¤u§@¶ & " §ó·s: " & ·Ç«h³æ¸¹ & " §¹²¦"
- End If
- End With
- With ¤u§@¶³æ¸¹_Rng
- .Value = ·Ç«h³æ¸¹_Rng.Value
- .BorderAround ColorIndex:=3, Weight:=xlThick
- End With
- End Sub
- Sub File_settings(xFile As Workbook, ¤u§@¶ As String) 'Àɮ׳]©w
- Dim xPath As String
- xPath = ThisWorkbook.Path & "\"
- If UCase(¤u§@¶) <> UCase("ERP_Data.XLSX") Then xPath = xPath & "FromERP\"
- On Error Resume Next
- Set xFile = Workbooks(¤u§@¶)
- If Err > 0 Then Set xFile = Workbooks.Open(xPath & ¤u§@¶)
- If xFile.Name = "" Then
- MsgBox "½Ð¬d¬Ý " & vbLf & xPath & vbLf & "¬O§_¦³ [" & ¤u§@¶ & "]"
- End
- End If
- End Sub
½Æ»s¥N½X |
|