- ©«¤l
- 406
- ¥DÃD
- 8
- ºëµØ
- 0
- ¿n¤À
- 453
- ÂI¦W
- 0
- §@·~¨t²Î
- WINDOWS 7
- ³nÅ骩¥»
- 2007
- ¾\ŪÅv
- 20
- ©Ê§O
- ¨k
- ¨Ó¦Û
- ¥xÆW
- µù¥U®É¶¡
- 2015-2-7
- ³Ì«áµn¿ý
- 2021-7-31
|
¦^´_ 20# papaya
§âExcelÀÉ©ñ¨ì ¦P¸ô®|¤Uªº"xlsÀÉ" ¸ê®Æ§¨«á¡A¦A°õ¦æ´N¥i¥H¤F
¥i¦Û¦æ§ï¸ô®|¦ì¸m(קïµ{¦¡¸Ì±ªº "xlsPath")
¦Ü©ó¤@¶}©lªºcsvÀÉ¡A§A¥i¥H¥t¼gµ{¦¡ÂনxlsÀÉ
´ú¸ÕÀÉ¥u¦³4Ó¡A©Ò¥H¤£·|ªá¤Óªø®É¶¡ (Àɮ׶V¤Ö¡A®É¶¡¶Vµu)
¦Ü©ó§A쥻ªº¤W¦ÊÓÀɮסA¥i¯à·|ªá¤W¼Æ¤ÀÄÁ
µ{¦¡¦p¤U
Private Sub CommandButton1_Click()
Application.ScreenUpdating = False
Application.DisplayAlerts = False
Dim Arr, ¦¹ªí As Worksheet, ¤é´Á As Date, tim!, rg As Range, Rn&, xlsNm$, sh
Dim Key$, Item$, xlsPath$, xlsÀÉ$, K1$, K2$, K3$, Ri&
Set D = CreateObject("Scripting.Dictionary")
Arr = Array("¤C¬F", "¤K¨ö", "¤¦æ", "¤»¨R", "¥Í¨v", "¦X¼Æ", "§¡È", "§À¼Æ")
Set ¦¹ªí = ActiveSheet
'---------------------------------------------
'1_¥ý³]¥ß1Ó¥i¿é¤J¤é´Á(yyyymmdd)ªºInputBox
¤é´Á = InputBox("½Ð¿é¤J¤é´Á¡A®æ¦¡Ex:2020/07/07", "¿é¤J¤é´Á")
If IsEmpty(¤é´Á) Then Exit Sub
'ÀɮצWºÙ="¤j¼Ö³z_¿òº|ªÅÁ`²Îpªí_¿é¤JInputBoxªº¤é´Á¡¨
xlsNm = "¤j¼Ö³z_¿òº|ªÅÁ`²Îpªí_" & Format(¤é´Á, "mmdd")
'Àˬd¬O§_¤w¦³ÀÉ®×(ÁקK«Âаõ¦æ)
Àˬd$ = Dir(ThisWorkbook.Path & "\" & xlsNm & ".xls*")
If Àˬd <> "" Then
re% = MsgBox("¦¹Àɮפw¦s¦b¡A½Ð½T»{¬O§_Âл\?", vbYesNo)
If re = vbNo Then Exit Sub Else Kill ThisWorkbook.Path & "\" & Àˬd
End If
tim = Timer '¶}©lp®É
'¤ñ¹ï¤é´Á
Set rg = Range([A1], [A1].End(4)).Find(¤é´Á, , , xlWhole)
If Not rg Is Nothing Then Rn = rg.Row
'¦pªG¸ÓB¡JH="¡¨®É¡A«hArrªºA1¤]="¡¨
If Rn = 0 Then MsgBox "§ä¤£¨ì¤é´Á": Exit Sub
For Each sh In Arr
With Sheets(sh): ¦¹ªí.Activate
'2_¸Ó¤é´Á¶ñ¤J"¤C¬F","¤K¨ö","¤¦æ","¤»¨R","¦X¼Æ","¥Í¨v","§¡È","§À¼Æ"ªº¦U¤u§@ªí
.[A1] = Format(¤é´Á, "yyyy/mm/dd")
'¨Ã±NDATAªºAÄæ=X¤é´Áªº¤U1¦C¤§B¡JH¼Æȶñ¤J
.[A3].Resize(7) = Application.Transpose(Cells(Rn + 1, 2).Resize(, 7))
End With
Next
'---------------------------------------------
'±NÄæ¦ì¸ê®Æ¸Ë¶i¦r¨å(¨Ñ«á±¬d¸ß)+²MªÅµ{¦¡Àɤu§@ªí¸ê®Æ
For Each sh In Arr: With Sheets(sh)
Rn = [B5000].End(3).Row
For R = 2 To Rn
If .Cells(R, 2) <> "" Then
'§â3ºØÃöÁä¦r²Õ¦X°_¨Ó·í¦r¨åªºKey (CÄæ¦r¦ê¤¤¦³ªÅ¥Õ³´¨À)
Key = .Name & "-" & .Cells(R, 2) & "-" & Replace(.Cells(R, 3), " ", "")
D(Key) = R 'Item©ñ'¦C¸¹'
.[E2].Resize(Rn - 1, 14).ClearContents '²MªÅ¸ê®Æ
End If
Next R
End With: Next sh
'-----------------------------------------------
xlsPath = ThisWorkbook.Path & "\xlsÀÉ\" '²Î¤@§âxls©ñ¦bxlsÀɸê®Æ§¨ -¥i¦Û¦æקï¸ê®Æ§¨¦WºÙ~
xlsÀÉ = Dir(xlsPath & "*.xls*")
Do While xlsÀÉ <> ""
K1 = Replace(Split(xlsÀÉ, "-")(2), "±Æ§Ç", "")
K2 = Split(xlsÀÉ, "-")(4)
K3 = Split(xlsÀÉ, "-")(5)
Key = K1 & "-" & K2 & "-" & K3
If D.Exists(Key) Then '¬d¦r¨å´M§ä¬O§_¦³Äæ¦ì
With Workbooks.Open(xlsPath & xlsÀÉ).Sheets(1)
'Step_3¡G¥HStep_1ªºA1¤é´Á(©Î=InputBox¿é¤Jªº¤é´Á)·j´MAZÄ椤ªº¬Û¦P¤é´Á
Set rg = .Range(.[AZ1], .[AZ1].End(4)).Find(¤é´Á, , , xlWhole)
'Step_4¡G±NStep_3 ·j´M¨ìªº¤é´Á¤§¤W1¦CªºBA¡JBS¤º®e¡A½Æ»s¶K¤WStep_1¬Û¹ïÀ³ªºEÄæÀx¦s®æ(=E7)
If Not rg Is Nothing Then Ri = rg.Row - 1 Else .Parent.Close False: GoTo ¤U¤@ÀÉ
¦¹ªí.Parent.Sheets(K1).Cells(D(Key), "E").Resize(, 14) = .Cells(Ri, "BA").Resize(, 14).Value
.Parent.Close False 'Ãö³¬xlsÀÉ
End With
End If
¤U¤@ÀÉ: xlsÀÉ = Dir
Loop
'-------------------------------------------------------
'3_±N§¹¦¨ªº¤u§@ªí¿é¥X¬°1Ó¿W¥ßÀÉ®×
With Workbooks.Add
For Each sh In Arr
¦¹ªí.Parent.Sheets(sh).Copy After:=.Sheets(.Sheets.Count) '½Æ»sArr¦U¤u§@ªí¤º®e
Next
.Sheets(Array(1, 2, 3)).Delete
.SaveAs ThisWorkbook.Path & "\" & xlsNm '¨Sµ¹°ÆÀɦW¡AªO·sª©Excel³£¾A¥Î
.Close True
End With
[Q2] = Round(Timer - tim, 2) & "’"
End Sub
Àɮצp¤U¡A¦³°ÝÃD¦A»¡¹Æ
¤j¼Ö³z.rar (679.52 KB)
|
|