ªð¦^¦Cªí ¤W¤@¥DÃD µo©«

[µo°Ý] ·j´M²Å¦X±ø¥óªº­q³æ¸¹½X

¥»©«³Ì«á¥Ñ 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´M­q³æ©ú²Óªíªº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(©Ò¥H­n¯à¦Û°Ê°»´ú¸ê®Æªº³Ì¥½ºÝ,¦pªG¦³¥þ¦CªÅ¥Õ(«D¥þ¦CªÅ¥Õ¤£ºâ¬OªÅ¥Õ),¨äªÅ¥Õªº²Ä¤@¦C(­Y¦³ªÅ¥Õ¦C«á¦A¥X²{ªº¸ê®Æµø¦PªÅ¥Õ)§Y¬O¶K·s¸ê®Æªº¦a¤è.
********************************
  1. Option Explicit
  2. Dim ¥ØªºÀÉ As Workbook, ¨Ó·½ÀÉ As Workbook
  3. Dim ·Ç«h³æ¸¹ As String, ·Ç«h³æ¸¹_Rng As Range
  4. Dim Äæ¦ì As String, ¤u§@­¶ As String, Msg As String
  5. Sub Main()
  6.     Dim Table As Range, Sh As Worksheet, i As Integer
  7.     Msg = ""
  8.     With ThisWorkbook.Sheets("VBA«ü¥O")           '³]©w·Ç«h½d³ò
  9.         Set Table = .Range("G2", .Range("G2").End(xlDown)).Resize(, 2)   '
  10.     End With
  11.     File_settings ¥ØªºÀÉ, "ERP_Data.XLSX"    '³]©w¥ØªºÀÉ
  12.     For i = 1 To Table.Rows.Count
  13.         File_settings ¨Ó·½ÀÉ, Table.Cells(i, 1) & ".XLSX"  '³]©w¨Ó·½ÀÉ
  14.         ·Ç«h³æ¸¹ = Table.Cells(i, 2)          'Ū¨ú·Ç«h
  15.         ¤u§@­¶ = Mid(Table.Cells(i, 1), 1, 2)    '¥ØªºÀɪº¤u§@ªí¦WºÙ
  16.         Äæ¦ì = IIf(¤u§@­¶ = "­q³æ" Or ¤u§@­¶ = "¶i³f" Or ¤u§@­¶ = "»â®Æ", "C:C", "B:B") '¥ØªºÀɪº¤u§@ªíªºÄæ¦ì
  17.         xSearch
  18.         ¨Ó·½ÀÉ.Close False
  19.     Next
  20.     '******************************
  21.     '¥ØªºÀÉ.Close True   ¼È®É¤£¦sÀÉ
  22.     '******************************
  23.     If Msg <> "" Then MsgBox Msg
  24. End Sub
  25. Private Sub xSearch()
  26.     Dim D As Object, M, ¤u§@­¶ As String
  27.     Set D = CreateObject("SCRIPTING.DICTIONARY") '¦r¨åª«¥ó
  28.     With ¨Ó·½ÀÉ.Sheets(1) '.Range("b:b")          '¨Ó·½ÀɲĤ@­Ó¤u§@ªíªºBÄæ
  29.         .Cells.Sort .Range("B1"), 1, Header:=xlYes   '±Æ§Ç
  30.         M = Application.Match(·Ç«h³æ¸¹, .Range("b:b").Cells, 0)
  31.         '**********************************
  32.         If IsError(M) Then Exit Sub  '¨Ó·½ÀɨS¦³§ä¨ì·Ç«h,Â÷¶}³oµ{¦¡ (¤£³B²z)
  33.         '**§ä¨ì·Ç«h,³]©w·Ç«hªº¸ê®Æ½d³ò
  34.         With .Range("b:b")
  35.             Do While .Cells(M) = ·Ç«h³æ¸¹
  36.                 '.Range("B" & M & ":BA" & M) -> ¦@27Äæ
  37.                 If TypeName(D(.Cells(M).Value)) <> "Range" Then
  38.                     Set D(·Ç«h³æ¸¹) = .Range("a" & M).Resize(, 27)
  39.                 Else
  40.                     Set D(·Ç«h³æ¸¹) = Union(D(·Ç«h³æ¸¹), .Range("a" & M).Resize(, 27))
  41.                 End If
  42.                 M = M + 1
  43.             Loop
  44.         End With
  45.         Set ·Ç«h³æ¸¹_Rng = D(·Ç«h³æ¸¹)
  46.     End With
  47.     ¥ØªºÀÉ_·Ç«h³æ¸¹
  48. End Sub
  49. Private Sub ¥ØªºÀÉ_·Ç«h³æ¸¹()
  50.     Dim M As Variant, D As Object, xRng As Range, i As Integer, ¤u§@­¶³æ¸¹_Rng As Range
  51.    
  52.     With ¥ØªºÀÉ.Sheets(¤u§@­¶)
  53.         '¥ØªºÀɪº¤u§@­¶¦³µL·Ç«h³æ¸¹
  54.         M = Application.Match(·Ç«h³æ¸¹, .Range(Äæ¦ì), 0)
  55.         '**************************
  56.         If IsError(M) Then   'µL·Ç«h³æ¸¹
  57.             M = Split(.UsedRange.Address, "$")
  58.             M = M(UBound(M))       '¤u§@­¶³Ì©³ºÝªº¦C
  59.             Do While Application.CountA(.Rows(M)) > 1  '¥²»Ý¨S¦³¸ê®Æ
  60.                 M = M + 1
  61.             Loop
  62.             '*********************************
  63.             Set ¤u§@­¶³æ¸¹_Rng = .Range(Äæ¦ì).Cells(M).Resize(·Ç«h³æ¸¹_Rng.Rows.Count, ·Ç«h³æ¸¹_Rng.Columns.Count)
  64.             Msg = Msg & vbLf & ¤u§@­¶ & " ¥[¤J: " & ·Ç«h³æ¸¹
  65.         Else       ''¦³·Ç«h³æ¸¹
  66.             Set D = CreateObject("SCRIPTING.DICTIONARY")
  67.             .Cells.Sort .Range(Äæ¦ì).Cells(1), 1, Header:=xlYes            '¥ý±Æ§Ç
  68.             With .Range(Äæ¦ì)
  69.                 M = Application.Match(·Ç«h³æ¸¹, .Cells, 0)  '´M§ä³æ¸¹¦C¸¹
  70.                 '³]©w ¤u§@­¶·Ç«h³æ¸¹ªº½d³ò*********
  71.                 Do While .Cells(M) = ·Ç«h³æ¸¹
  72.                     If TypeName(D(.Cells(M).Value)) <> "Range" Then
  73.                         Set D(·Ç«h³æ¸¹) = .Range("a" & M).Resize(, 27)
  74.                     Else
  75.                         Set D(·Ç«h³æ¸¹) = Union(D(·Ç«h³æ¸¹), .Range("a" & M).Resize(, 27))
  76.                     End If
  77.                     M = M + 1
  78.                 Loop
  79.             End With
  80.             With D(·Ç«h³æ¸¹)
  81.                 If .Rows.Count > ·Ç«h³æ¸¹_Rng.Rows.Count Then  '¤u§@­¶³æ¸¹¦C¼Æ>·Ç«h³æ¸¹¦C¼Æ
  82.                     For i = .Rows.Count To ·Ç«h³æ¸¹_Rng.Rows.Count + 1 Step -1
  83.                         Rows(i).EntireRow.Delete                    '¾ã¦C§R°£
  84.                     Next
  85.                 ElseIf .Rows.Count < ·Ç«h³æ¸¹_Rng.Rows.Count Then   '¤u§@­¶³æ¸¹¦C¼Æ<·Ç«h³æ¸¹¦C¼Æ
  86.                     For i = .Rows.Count + 1 To ·Ç«h³æ¸¹_Rng.Rows.Count
  87.                         Rows(i + 1).EntireRow.Insert                '·s¼W¤@¦C
  88.                     Next
  89.                 End If
  90.             End With
  91.             Set ¤u§@­¶³æ¸¹_Rng = D(·Ç«h³æ¸¹).Resize(D(·Ç«h³æ¸¹).Rows.Count)
  92.             Msg = Msg & vbLf & ¤u§@­¶ & " §ó·s: " & ·Ç«h³æ¸¹ & " §¹²¦"
  93.         End If
  94.     End With
  95.     With ¤u§@­¶³æ¸¹_Rng
  96.         .Value = ·Ç«h³æ¸¹_Rng.Value
  97.         .BorderAround ColorIndex:=3, Weight:=xlThick
  98.     End With
  99. End Sub
  100. Sub File_settings(xFile As Workbook, ¤u§@­¶ As String) 'Àɮ׳]©w
  101.     Dim xPath As String
  102.     xPath = ThisWorkbook.Path & "\"
  103.     If UCase(¤u§@­¶) <> UCase("ERP_Data.XLSX") Then xPath = xPath & "FromERP\"
  104.     On Error Resume Next
  105.     Set xFile = Workbooks(¤u§@­¶)
  106.     If Err > 0 Then Set xFile = Workbooks.Open(xPath & ¤u§@­¶)
  107.     If xFile.Name = "" Then
  108.         MsgBox "½Ð¬d¬Ý " & vbLf & xPath & vbLf & "¬O§_¦³ [" & ¤u§@­¶ & "]"
  109.         End
  110.     End If
  111. End Sub
½Æ»s¥N½X
·P®¦ªº¤ß......(¦b³Â»¶®a±Ú°Q½×°Ï.¥Î¤ß¾Ç²ß·|¦³¶i¨Bªº)
¦ý¸ê·½µL­­,«á´©¦³­­,  ¤@¤Ñ1¤¸ªºÃÙ§U,¤H¤H¦³¯à¤O.

TOP

¦^´_ 7# Hsieh

¤j¤j,

§Ú·Q±N§A¼gªº³o­Óµ{¦¡®M¨ì¥H¤U³o´X­Ó¼Ò¦¡¤¤¡A¥Ø«e¥u¥ý¹Á¸Õ"­q³æ©ú²Óªí",¦ý¤@ª½¤£¦¨¥\¡I¥i§_½Ð§A¥Ü½d¤U¦p¦ó­×§ïµ{¦¡¤º®e¡H    ¥X³f¤å¥ó³sµ².rar (97.66 KB)

¨Ó·½ÀÉ Q:\00_¬ì¼Ý\¥X³f¤å¥ó³sµ²\FromERP\
­q³æ©ú²Óªí.xlsx
½ÐÁʳæ©ú²Óªí.xlsx
±ÄÁʳæ©ú²Óªí.xlsx
¶i³f³æ©ú²Óªí.xlsx
»â®Æ³æ©ú²Óªí.xlsx
¥X³f³æ©ú²Óªí.xlsx

¥ØªºÀÉ Q:\00_¬ì¼Ý\¥X³f¤å¥ó³sµ²\ERP_Data.xlsx
­q³æ.sheet
½ÐÁÊ.sheet
±ÄÁÊ.sheet
¶i³f.sheet
»â®Æ.sheet
¥X³f.sheet

·Ç«h¦s©ñªºÀɮפÎÀx¦s®æ
Q:\00_¬ì¼Ý\¥X³f¤å¥ó³sµ²\VBA³øªí«ü¥O.xlsm
­q³æ©ú²Óªí            H2
½ÐÁʳæ©ú²Óªí        H3
±ÄÁʳæ©ú²Óªí        H4
¶i³f³æ©ú²Óªí        H5
»â®Æ³æ©ú²Óªí        H6
¥X³f³æ©ú²Óªí        H7

­q³æ©ú²Óªíªº®Mªí¼Ò¦¡¬°¡G
1. ¥HVBA³øªí«ü¥O.xlsm H2¬°·Ç«h,·j´M­q³æ©ú²Óªíªº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(©Ò¥H­n¯à¦Û°Ê°»´ú¸ê®Æªº³Ì¥½ºÝ,¦pªG¦³¥þ¦CªÅ¥Õ(«D¥þ¦CªÅ¥Õ¤£ºâ¬OªÅ¥Õ),¨äªÅ¥Õªº²Ä¤@¦C(­Y¦³ªÅ¥Õ¦C«á¦A¥X²{ªº¸ê®Æµø¦PªÅ¥Õ)§Y¬O¶K·s¸ê®Æªº¦a¤è.

ª`·N¨Æ¶µ:
1. ¨Ó·½ÀɤΥتºÀɪº¸ê®Æ³£¨Ó¦Û¨t²ÎDownloadªº³øªí,©Ò¥H¸ê®Æ¦h¹è¬O·|Åܰʪº
2. ·Ç«h¦s©ñªºH2~H7,¨ä­È¤]·|ÀHµÛ»Ý¨D¦ÓÅÜ°Ê
3. ¥ØªºÀɨC­Ósheet³£¦³³]©w²Õ¦¨¸s²Õ,¬O§_À³¦³¥ý¥´¶}¸s²Õªº°Ê§@,¸ê®Æ¤~·|¶K¥¿½T¦ì¸m¡H
4. ·í¸ê®Æ¶K§¹¥H«á,­n¦AÁôÂøs²Õ

TOP

¦^´_ 7# Hsieh

§Ú¦Û¤v­×§ï¤Fµ{¦¡¦ý¨S¦³¶Kªº°Ê§@,½Ð°Ý
Row.Count­n¦p¦ó¼Æ¡HOffset(1)¤S¥Nªí¤°»ò¡H
ÁÙ¦³²Ä¤G¦æªºµ{¦¡­n«ç»ò¸ÑŪ¡H
  1. If a Is Nothing Then Set a = .Cells(.Rows.Count, 4).End(xlUp).Offset(1) '­ì¸ê®Æ¤£¦s¦b·Ç«h¸ê®Æ
  2.        .Range("A" & a.Row & ":AA" & .Rows.Count).ClearContents
½Æ»s¥N½X

TOP

¦^´_ 7# Hsieh
¤j¤j,
§Ú­×§ï¤F¨Ç¤p¦a¤è,²{¦b¶K¤W®É¥¿±`¤F.
  1. Sub copy_all()
  2. Dim ws() '¤w¸g¶}±Òµøµ¡
  3. books = Array("®w¦s¸ê®Æªí.xlsx", "®w¦s.xlsx") '±ý¶}±ÒÀÉ®×
  4. mypath = ThisWorkbook.Path '¦s©ñÀɮ׸ê®Æ§¨
  5. For Each W In Windows '¤w¸g¶}±Òµøµ¡
  6.    ReDim Preserve ws(s)
  7.    ws(s) = W.Caption
  8.    s = s + 1
  9. Next
  10. For Each b In books '´ú¸ÕÀɮ׬O§_¶}±Ò
  11.    If UBound(Filter(ws, b)) = -1 Then Workbooks.Open (mypath & "\" & b) 'ÀÉ®×¥¼¶}±Ò«h¶}±Ò
  12. Next
  13. x = ThisWorkbook.Sheets(1).[H2] '·Ç«h
  14. With Workbooks(books(0)).Sheets(1) '®w¦s¸ê®Æªí.xlsx
  15.     Set a = .Columns("D").Find(x, lookat:=xlWhole) '§ä·Ç«h¦ì¸m
  16.     If a Is Nothing Then MsgBox "§ä¤£¨ì·Ç«h¦ì¸m": End
  17.     Set Rng = .Range(a.Offset(, -3), a.End(xlDown).Offset(, 23)) 'B:AAÄæ¸ê®Æ
  18.     'MsgBox Rng.Address
  19.     With Workbooks(books(1)).Sheets(1) '®w¦s.xlsx
  20.        Set a = .Columns("D").Find(x, lookat:=xlWhole) '§ä·Ç«h¦ì¸m
  21.        If a Is Nothing Then Set a = .Cells(.Rows.Count, 4).End(xlUp).Offset(1) '­ì¸ê®Æ¤£¦s¦b·Ç«h¸ê®Æ
  22.        .Range("A" & a.Row & ":AA" & .Rows.Count).ClearContents
  23.           a.Offset(, -3).Resize(Rng.Rows.Count, 27).Value = Rng.Value '¼g¤J·s¸ê®Æ
  24.           'a.Offset(, -3).Resize(Rng.Rows.Count, 1) = Rng.Columns(5).Value '¼g¤JAÄæ½s¸¹
  25.           MsgBox "¸ê®Æ¤w§ó·s"
  26.     End With
  27. End With
  28. End Sub
½Æ»s¥N½X

TOP

¦^´_ 7# Hsieh

¤j¤j,
1) ¸g´ú¸Õ,¶K¸ê®Æªº®É­Ô,¥¦·|§âAAÄ檺¸ê®Æ¶K¨ìAÄæ,µM«á¨ä¥L¸ê®Æ¦V¥k²¾¤@­ÓÄæ¦ì....½Ð°Ý­n¦p¦ó­×¥¿?
2) ¦]¬°³o­Óµ{¦¡,§ÚÁÙ·|¨Ï¥Î¦b¨ä¥Lªº¤å¥ó¤W¡Abooks = Array("®w¦s¸ê®Æªí.xlsx", "®w¦s.xlsx"),¬O§_ÀɦW¤£¦P®É,§Ú¥u­n§ï¤£¦PÃC¦âªºÀɦW§Y¥i¡H¨ä¥LÀɦW¦pµ{¦¡¤¤ªºSheets(1)§Ú¤£¥Î°Ê¥¦,¬O¶Ü¡H
3) ·í§ÚªºÀɮצs©ñ¸ô®|¤£¦P®É,§Ú»Ý­n­×§ï¤°»ò¦a¤è¶Ü¡H
4) ¦ý¨C¥÷³øªíªº¶K¤W¦ì¸m¤£¦P,¦pªG§Ú­n¦Û¤v­×§ï¡A¥HVBA³øªí«ü¥O.xlsmªºVBA«ü¥O.sheet H2Àx¦s®æ¬°·j´M·Ç«h¥h·j´M¥ØªºÀÉCÄæ,¦ý¬O¶K¤W­n¦bBÄæ,§Ú­n«ç»ò­×§ï?

¤£¦n·N«ä,³Â·Ð§A¤F...

TOP

¦^´_ 6# PJChen
  1. Sub copy_all()
  2. Dim ws() '¤w¸g¶}±Òµøµ¡
  3. books = Array("®w¦s¸ê®Æªí.xlsx", "®w¦s.xlsx") '±ý¶}±ÒÀÉ®×
  4. mypath = ThisWorkbook.Path '¦s©ñÀɮ׸ê®Æ§¨
  5. For Each w In Windows '¤w¸g¶}±Òµøµ¡
  6.    ReDim Preserve ws(s)
  7.    ws(s) = w.Caption
  8.    s = s + 1
  9. Next
  10. For Each b In books '´ú¸ÕÀɮ׬O§_¶}±Ò
  11.    If UBound(Filter(ws, b)) = -1 Then Workbooks.Open (mypath & "\" & b) 'ÀÉ®×¥¼¶}±Ò«h¶}±Ò
  12. Next
  13. x = ThisWorkbook.Sheets(1).[H2] '·Ç«h
  14. With Workbooks(books(0)).Sheets(1) '®w¦s¸ê®Æªí.xlsx
  15.     Set a = .Columns("D").Find(x, lookat:=xlWhole) '§ä·Ç«h¦ì¸m
  16.     If a Is Nothing Then MsgBox "§ä¤£¨ì·Ç«h¦ì¸m": End
  17.     Set Rng = .Range(a.Offset(, -2), a.End(xlDown).Offset(, 23)) 'B:AAÄæ¸ê®Æ
  18.     MsgBox Rng.Address
  19.     With Workbooks(books(1)).Sheets(1) '®w¦s.xlsx
  20.        Set a = .Columns("D").Find(x, lookat:=xlWhole) '§ä·Ç«h¦ì¸m
  21.        If a Is Nothing Then Set a = .Cells(.Rows.Count, 4).End(xlUp).Offset(1) '­ì¸ê®Æ¤£¦s¦b·Ç«h¸ê®Æ
  22.        .Range("A" & a.Row & ":AA" & .Rows.Count).ClearContents
  23.           a.Offset(, -2).Resize(Rng.Rows.Count, 26).Value = Rng.Value '¼g¤J·s¸ê®Æ
  24.           a.Offset(, -3).Resize(Rng.Rows.Count, 1) = Rng.Columns(5).Value '¼g¤JAÄæ½s¸¹
  25.           MsgBox "¸ê®Æ¤w§ó·s"
  26.     End With
  27. End With
  28. End Sub
½Æ»s¥N½X
¾Ç®üµL²P_¤£®¢¤U°Ý

TOP

¦^´_ 5# Hsieh

¤j¤j,

§Ú´ú¸Õ¤F´X¦¸,µo²{¤@¨Ç°ÝÃD,­n¦A³Â·Ð±z­×§ï¤U.

1. ¦b´ú¸Õªº®É­Ô,§Ú¬G·N§â"®w¦s.xlsx"ªº¸ê®Æ§R°£,¥u«O¯d¦Ü1000¦C.
2. "®w¦s¸ê®Æªí"¦@1059¦C(³£¨S¦³§R°£), ·í§Ú§â"VBA³øªí«ü¥O.xlsm" H2ªºÅܼƧאּM1®É,¥¦À³¸Ó­n±q"®w¦s¸ê®Æªí"ªºA1:AA1059½Æ»s¨ì"®w¦s.xlsx"ªºA1:AA1059¶Kº¡,¦ý¥¦¥u¸ß°Ý¦³9¦C·s¸ê®Æ¬O§_­n§ó·s.
3. ·í§Ú§â"®w¦s.xlsx"ªº¸ê®ÆAÄæ¸ê®Æ«O¯d10¦C,¨ä¾lA11¥H«á¬°ªÅ¥Õ®É¡A¥¦¤]µLªk¥¿±`§ó·s¸ê®Æ

P.S. ¤j¤j¼gªºµ{¦¡¦]¬°¤£¬O¥¨¶°¦¡ªº,§Ú¦³¬Ý¨S¦³À´,±z¥i§_À°§Úµù¸Ñ¦A§ó¸Ô²Ó¨Ç¡A¦]¬°³o­Óµ{¦¡,§Ú·|À³¥Î¨ì«Ü¦h¸ê®Æ¤W¡A¸Ô²Óªºµù¸Ñ¦³§U©ó§Ú¤é«áªº¤p­×§ï.  
ªþ¤W§Ú´ú¸ÕªºÀÉ®× ¨ÌÅܼƷj´M¸ê®Æ2.rar (298.47 KB)

¥ýÁÂÁ¤F.

TOP

¦^´_ 4# PJChen

°Ñ¦Ò¬Ý¬Ý
  1. Sub copy_all()
  2. Dim ws() '¤w¸g¶}±Òµøµ¡
  3. books = Array("®w¦s¸ê®Æªí.xlsx", "®w¦s.xlsx") '±ý¶}±ÒÀÉ®×
  4. mypath = ThisWorkbook.Path '¦s©ñÀɮ׸ê®Æ§¨
  5. For Each w In Windows '¤w¸g¶}±Òµøµ¡
  6.    ReDim Preserve ws(s)
  7.    ws(s) = w.Caption
  8.    s = s + 1
  9. Next
  10. For Each b In books '´ú¸ÕÀɮ׬O§_¶}±Ò
  11.    If UBound(Filter(ws, b)) = -1 Then Workbooks.Open (mypath & "\" & b) 'ÀÉ®×¥¼¶}±Ò«h¶}±Ò
  12. Next
  13. x = ThisWorkbook.Sheets(1).[H2] '·Ç«h
  14. With Workbooks(books(0)) '®w¦s¸ê®Æªí.xlsx
  15.     Set a = .Sheets(1).Columns("D").Find(x, lookat:=xlWhole) '§ä·Ç«h¦ì¸m
  16.     If a Is Nothing Then MsgBox "§ä¤£¨ì·Ç«h¦ì¸m": End
  17.     k = Application.CountIf(a.EntireColumn, x) '¦X¥G·Ç«h¦C¼Æ
  18.     Set Rng = .Sheets(1).Cells(a.Row, "B").Resize(k, 26) 'B:AAÄæ¸ê®Æ
  19.     With Workbooks(books(1)) '®w¦s.xlsx
  20.        k1 = Application.CountIf(.Sheets(1).Columns("D"), x) '¦X¥G·Ç«h¦C¼Æ
  21.        Set a = .Sheets(1).Columns("D").Find(x, lookat:=xlWhole) '§ä·Ç«h¦ì¸m
  22.        If a Is Nothing Then Set a = .Sheets(1).Cells(.Sheets(1).Rows.Count, 4).End(xlUp).Offset(1) '­ì¸ê®Æ¤£¦s¦b·Ç«h¸ê®Æ
  23.        yn = MsgBox("­ì¸ê®Æ" & k1 & "¦C¡A·s¸ê®Æ" & k & "¦C¡A¬O§_½Æ»s?", vbYesNo)
  24.        If yn = 6 Then
  25.           a.Offset(, -2).Resize(k, 26).Value = Rng.Value '¼g¤J·s¸ê®Æ
  26.           MsgBox "¸ê®Æ¤w§ó·s"
  27.         Else
  28.           MsgBox "¸ê®Æ¥¼§ó·s", 48
  29.        End If
  30.     End With
  31. End With
  32. End Sub
½Æ»s¥N½X
¾Ç®üµL²P_¤£®¢¤U°Ý

TOP

¦^´_ 3# Hsieh

¤j¤j¦n,

§Ú§ìªº³øªí¤é´Á°Ï¶¡¥i¯à´N¬O·í¤ë¥÷ªº,ExcelÀɤ¤ªº¸ê®Æ·|²Ö¿n¤ñ¸û¦h¸ê®Æ,©Ò¥H§Ú¦bVBA³øªí«ü¥O.xlsm H2¤¤«ü©w¤@­Ó³æ¸¹¦WºÙ,¦Ó¤@­Ó³æ¸¹¥i¯à¦³«Ü¦hµ§,©Ò¥H§Ú­n«ü©w¥¦¥i¥H±q§ä¨ìªº²Ä¤@µ§¶}©l¶K¤W,³o¼Ë´N¤£·|»\±¼§Ú»Ý­nªº¸ê®Æ,¦P®É¤]¥i¥H§ó·s§Ú­nªº¸ê®Æ.

¥u¬O§Ú¤â¤W¥¿¦n¦³³o­Ó¸ê®Æ,©Ò¥H´N°½Ãi¥Î³o­ÓÀɨӸ߰Ý,¤£¹LÆ[©À¬O¬Û¦Pªº.

TOP

¦^´_ 2# PJChen

¶K¤Wªº¦ì¸m¬O®w¦sÀɮתº¦ì¸m¡A­Y­ì¨Ó®w¦sªºµ§¼Æ¤£¦P¸Ó¦p¦ó³B²z?
­Yµ§¼Æ¬Û¦P´N·|ª½±µÂл\­ì¦³¸ê®Æ¡A³o¬O§Aªº»Ý¨D¶Ü?
­Yµ§¼Æ±Ð­û¸ê®Æ¦h¡A«h·|¼vÅT¤£¦P·Ç«hªº¸ê®Æ¡A³o¨Ç¸ò®w¦sÆ[©À¦n¹³³£¤£²Å¦X
¾Ç®üµL²P_¤£®¢¤U°Ý

TOP

        ÀR«ä¦Û¦b : ¯u¥¿ªº·R¤ß¡A¬O·ÓÅU¦n¦Û¤vªº³oÁû¤ß¡C
ªð¦^¦Cªí ¤W¤@¥DÃD