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

[µo°Ý] ¤U­Ó¤ë·sÀÉ

¦^´_ 12# ­ã´£³¡ªL

­ã¤j,
2¤ë¤w¸gµLªk´ú¸Õ,3¤ë¤S¬O31¤Ñ,©Ò¥H§Ú´ú¸Õ4¤ë
³o¥y
For i = mDay + 1 To 31: BK.Sheets(i & "").Delete: Next i '§R¤u§@ªí
»P«e­±ªºDim Lastday$, mDay%, xBK As Workbook¤£¦P,µLªk§R°£¤j©ó¤ë©³¤éªº¤u§@ªí,©Ò¥H§Ú§ï¬°
For i = mDay + 1 To 31: xBK.Sheets(i & "").Delete: Next i
§R°£¤j©ó¤ë©³¤éªº¤u§@ªí¥i°õ¦æ,¦ý¤S¦³¨ä¥L¦a¤è¥dÃö,½ÐÀ°¦£¬Ý¤U¬O§_§Ú¦³§Ë¿ùªº»yªk??
  1. Sub EX()
  2. Dim Path$, File$, i&, k&
  3. Dim Lastday$, mDay%, xBK As Workbook, BK As Workbook
  4. Dim myPath$, xFile$, m$, h$
  5. Lastday = DateSerial(Year(Date), Month(Date) + 3, 0) '¤U¤U­Ó¤ë¤ë©³
  6. mDay = Day(Lastday) '¤U­Ó¤ë¤Ñ¼Æ
  7. h = DateSerial(Year(Date), Month(Date) + 2, 1)  '³]©w¤U­Ó¤ë1¤é
  8. m = Format(h, "M¤ë") '³]©w¤U­Ó¤ë¥÷
  9. Application.ScreenUpdating = False  'Ãö³¬«Ì¹õ§ó·s
  10. Application.DisplayAlerts = False   '¤@¯ë´£Äµ¥Ü°T®§Ãö³¬
  11.     Path = "U:\a\1.¤U­Ó¤ë²z³f³æ\"  '¨Ó·½¸ê®Æ§¨
  12.     myPath = "U:\b\"                 '¥t¦s¥Øªº¸ê®Æ§¨

  13.         File = Dir(Path & "*.xlsx")          '¨Ó·½ÀɦW
  14.             Do While File <> ""
  15.                 With Workbooks.Open(Path & File)
  16.                         On Error Resume Next
  17.                         Sheets("1").Activate
  18.                         [A2] = Format(h, "M/D")   '¿é¤J«ü©w¤é´Á,¬°¤U­Ó¤ë1¤é
  19.                         ActiveWorkbook.Save '**¦sÀɤ£Ãö³¬
  20.                 End With

  21. Set xBK = Workbooks.Open(Path & File) '¶}±Ò«ü©wÀÉ®×

  22.             On Error Resume Next
  23.             For i = mDay + 1 To 31: xBK.Sheets(i & "").Delete: Next i '§R¤u§@ªí
  24.             On Error GoTo 0

  25.             For i = 1 To mDay
  26.                 With xBK.Sheets(i & "")
  27.                     .[A2] = .[A2].Value '­È¤Æ
  28.                     .[B1] = .[B1].Value '­È¤Æ
  29.                 End With
  30.             Next i
  31.                 For i = 1 To mDay  '¦b¤u§@ªí¤¤´`Àô
  32.                     With xBK.Sheets(i & "")
  33.                         Sheets("1").Activate
  34.                         For k = 1 To [U1]  '±NU1Àx¦s®æªº­È,§@¬°ÅܼƦs¨ú¦¸¼Æ,¨Ì§Ç©R¦WÀɮצW¨Ã¦sÀÉ
  35.                             [P1] = k   '«ü©wÀx¦s®æªº­È
  36.                             ActiveWorkbook.SaveAs filename:=myPath & [V2] & [G1] & " _" & m & ".xlsx" 'one by one ¦sÀÉk¦¸
  37.                         Next
  38.                             ActiveWorkbook.Close True   '¦sÀÉ«áÃö³¬ÀÉ®×
  39.                     End With
  40.                 Next i
  41.     File = Dir
  42.         Loop
½Æ»s¥N½X

TOP

¥»©«³Ì«á¥Ñ ­ã´£³¡ªL ©ó 2020-2-10 16:16 ½s¿è

Sub TEST()
Dim xPath$, xFile$, i&, k&
Dim Lastday$, mDay%, xBK As Workbook
Lastday = DateSerial(Year(Date), Month(Date) + 2, 0) '¤U­Ó¤ë¤ë©³
mDay = Day(Lastday) '¤U­Ó¤ë¤Ñ¼Æ
Set xBK = Workbooks.Open(xPath & xFile) '¶}±Ò«ü©wÀÉ®×
'-----------------------------------
Application.DisplayAlerts = False
On Error Resume Next
For i = mDay + 1 To 31: xBK.Sheets(i & "").Delete: Next i '§R¤u§@ªí
On Error GoTo 0
Application.DisplayAlerts = True
'-----------------------------------
For i = 1 To mDay
    With xBK.Sheets(i & "")
         .[A2] = .[A2].Value '­È¤Æ
              .[B1] = .[B1].Value '­È¤Æ
    End With
Next i
End Sub

¨ä¥¦»Ý¨D¦Û¦æ¥[¤J~~

===================================

TOP

¥»©«³Ì«á¥Ñ PJChen ©ó 2020-1-26 22:00 ½s¿è

¦^´_ 9# ­ã´£³¡ªL

½Ð°Ý­ã¤j,
¦P­ÓÀÉ®×,Sheet¥H1~31©R¦W,¨ä¤¤¤]¦³«D¼Æ¦rªº¤u§@ªí,§Ú»Ý­n¤@­Ó¥i¥H§R°£¤j©ó¤ë©³¤é¤u§@ªíªº¥\¯à(«D¼Æ¦rªº¤u§@ªí¤£§R,¥Ø«e±Æ§Ç,²Ä¤@­Ó¤u§@ªí¬°¤å¦r¤u§@ªí),¦pªG·í¤ë¥¿¦n¬O31¤Ñ,¤]³£¤£¥Î§R°£¤u§@ªí,
µ{¦¡½X«Üªø,§Ú¥uºI¨ú¤@³¡¥÷,¥H¤U³o¥y, ¤@ª½°õ¦æ±o«Ü©Ç,¦sÀɮɬ°2¤ë¥÷¤é´Á,2¤ë¥÷¦³29¤é,¥¦«o¥u§R°£29¡B31ªº¤u§@ªí,§Ú»Ý­n§R°£ªº¬O30¡B31ªº¤u§@ªí,½Ð°Ý¥i¥H«ç»ò­×¥¿µ{¦¡?
Sheets(j).Delete    '§R°£¤j©ó¤ë©³¤éªº¤u§@ªí
  1.     Dim Path As String, myPath As String, File As String, xFile As String, i As String, m As String, xd As Long, j As Long, xJ As Long, k As Long
  2.     i = DateSerial(Year(Date), Month(Date) + 1, 1)  '³]©w¤U­Ó¤ë1¤é
  3.     m = Format(i, "M¤ë") '³]©w¤U­Ó¤ë¥÷
  4.     xd = Format(DateSerial(Year(Date), Month(Date) + 2, 1) - 1, "D")   '¤U­Ó¤ë©³¤éÅܼÆ

  5. With Workbooks.Open(Path & File)
  6.                 For j = 2 To ActiveWorkbook.Sheets.Count  '±q#2¶}©lªº¤u§@ªí¤¤´`Àô
  7.                     ActiveWorkbook.Sheets(j).Activate
  8.                         [A2] = [A2].Value '­È¤Æ
  9.                         [B1] = [B1].Value '­È¤Æ
  10.                         
  11.                         If j > xd Then
  12.                             Sheets(j).Delete    '§R°£¤j©ó¤ë©³¤éªº¤u§@ªí
  13.                         End If
  14.                     Next
  15.                         Sheets("1").Activate
  16.                     For k = 1 To [U1]  '±NU1Àx¦s®æªº­È,§@¬°ÅܼƦs¨ú¦¸¼Æ,¨Ì§Ç©R¦WÀɮצW¨Ã¦sÀÉ
  17.                         [P1] = k   '«ü©wÀx¦s®æªº­È
  18.                         ActiveWorkbook.SaveAs filename:=myPath & [G1] & " _" & m & ".xlsx"  'one by one ¦sÀÉk¦¸
  19.                     Next
  20.                         ActiveWorkbook.Close True   '¦sÀÉ«áÃö³¬ÀÉ®×
  21.             End With
½Æ»s¥N½X

TOP

¦^´_ 9# ­ã´£³¡ªL

ÁÂÁ­ã¤j,
µy­×§ï¸ô®|,°õ¦æOK

TOP

´ú¸ÕÀÉ:
TEST001.rar (96.64 KB)

TOP

¦^´_ 6# PJChen


    ·|´`Àô¶Ü...§Ú¦Û¤v¦brunªº®É­Ô¬O¨S°ÝÃD°ÕXD

TOP

¦^´_ 5# »a³·

«á¨Ó§ï¦¨³o¼Ë´N¤£·|¤@ª½´`Àô¤F,²{¦b§Ú¥u³Ñ4~5ÁÙ¨S¦¨¥\....
  1.         Path = ".......\1.¤é¯Z²z³f´«ºâªí\"                 '¥t¦s¥Øªº¸ê®Æ§¨
  2.         File = Dir(Path & "*.xlsx")          '¨Ó·½ÀɦW
  3.             Do While File <> ""
  4.             Set mySheet = Workbooks("°Ó«~.xlsx").Worksheets("·s¤ë")
  5.             iRow = mySheet.Cells(Cells.Rows.Count, "C").End(xlUp).Row  '¬ÝCÄæ¦ì´Xµ§¸ê®Æ
  6. '>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> ¨Ó·½¸ê®Æ§¨ ²z³f³æ Sheets("¥X³f¼Æ")·s¼W.§R°£
  7.                 With Workbooks.Open(Path & File)
  8.                     ActiveWorkbook.Sheets("¥X³f¼Æ").Activate
  9.                     Range("A3:C" & iRow - 1).Value = mySheet.Range("A4:C" & iRow).Value  'iRow­pºâ¨Ó·½Àɪº¦C¼Æ,±qA4¶}©l,¥ØªºÀɱqA3¶}©l,·|¦h¶K¤@¦C,©Ò¥H¥ØªºÀÉ­n-1
  10.                     ActiveWorkbook.Close True   '¦sÀÉ«áÃö³¬ÀÉ®×
  11.                 End With
  12. '>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
  13.         File = Dir
  14.     Loop
  15. End Sub
½Æ»s¥N½X

TOP

¦^´_ 5# »a³·

¥ýÁÂÁ§Aªºµ{¦¡,
´ú¸Õµ²ªG:µ{¦¡·|¤@ª½´`Àô,°±¤£¤U¨Ó,³Ì«á­n«öESC¥h²×¤î¥¦,¥i¥H«ç»ò­×¥¿©O?......¥t
4)~5) ªº§PÂ_»yªk,­þ¦ì¤j¤j±Ð¾Ç¤@¤U¶Ü?
1) copy­È¨ì "1.¤U­Ó¤ë²z³f³æ_´ú¸Õ"¸ê®Æ§¨¤¤ªº¨C­ÓÀÉ®×Sheets("¥X³f¼Æ")ªºA3:C
2) ¦A¥HSheets("·s¤ë") A4:C©³§PÂ_¦C¼Æ
3) ·íSheets("¥X³f¼Æ")ªºA3:Cªº¦C¼Æ=Sheets("·s¤ë") A4:C «h¦sÀÉÃö³¬

4) ·íSheets("¥X³f¼Æ")ªºA3:Cªº¦C¼Æ>Sheets("·s¤ë") A4:C «h §R°£¦hªº¦C¼Æ ¦sÀÉÃö³¬
5) ·íSheets("¥X³f¼Æ")ªºA3:Cªº¦C¼Æ<Sheets("·s¤ë") A4:C «h §âDÄ椽¦¡©¹¤U½Æ¨î,¦p¦PSheets("·s¤ë") A4:C©³ ªº¦C¼Æ ¦sÀÉÃö³¬

TOP

¥»©«³Ì«á¥Ñ »a³· ©ó 2020-1-5 23:22 ½s¿è

¦^´_ 4# PJChen


    ¤p§Ì§Ú¸ÕµÛ§ï¤F¤@¤U¡A½ÐªA¥Î¡C

    ­ì¥»§A¼gªº§Ú¦³«O¯d¡AÅܦ¨µù¸Ñ±¡ªp¡A¥i¥H¸ò§Ú¼gªº°Ï¶ô¤ñ¹ï¤@¤U¡C

    ¦]¬°­n§ì°Ó«~ªºrow¼Æ¶q¡A©Ò¥H cells(rows.count,"C").end(xlup).row ¥²¶·¬O¥H...

    workbooks("°Ó«~.xlsx").WORKSHEETS("·s¤ë").cells(rows.count,"C").end(xlup).row¤U¥h¼g¡A¤~·|¥h§ì¨ì¸ÓSheetªºrow¼Æ¶q¡C

    «e´£¬Oworkbook °Ó«~¬O­n¶}±Òªºª¬ºA¡C Macro_T.zip (14.6 KB)

TOP

¥»©«³Ì«á¥Ñ PJChen ©ó 2019-12-29 18:04 ½s¿è

Dear,
¤§«e·Q­nªº°µªk§¹¥þ°µ¤£¥X¨Ó,§Ú·Q±Nµ{¦¡³o­Ó¥\¯à³æ¿W©Ô¥X¨Ó,¨Ï¤§Â²¤Æ
¥HWorkbooks("°Ó«~.xlsx").Sheets("·s¤ë") A4:C©³ ¬°¸ê®Æ¨Ó·½
1) copy­È¨ì "1.¤U­Ó¤ë²z³f³æ_´ú¸Õ"¸ê®Æ§¨¤¤ªº¨C­ÓÀÉ®×Sheets("¥X³f¼Æ")ªºA3:C
2) ¦A¥HSheets("·s¤ë") A4:C©³§PÂ_¦C¼Æ
3) ·íSheets("¥X³f¼Æ")ªºA3:Cªº¦C¼Æ=Sheets("·s¤ë") A4:C «h¦sÀÉÃö³¬
4) ·íSheets("¥X³f¼Æ")ªºA3:Cªº¦C¼Æ>Sheets("·s¤ë") A4:C «h §R°£¦hªº¦C¼Æ ¦sÀÉÃö³¬
5) ·íSheets("¥X³f¼Æ")ªºA3:Cªº¦C¼Æ<Sheets("·s¤ë") A4:C «h §âDÄ椽¦¡©¹¤U½Æ¨î,¦p¦PSheets("·s¤ë") A4:C©³ ªº¦C¼Æ ¦sÀÉÃö³¬

²{¦b°µ²Ä¤@­Ócopy¸ê®Æªº¥\¯à,¤@ª½µLªk¥¿±`¶K¸ê®Æ,¥i§_À°¦£¬Ý¤U?? ¤U­Ó¤ë²z³f³æ_´ú.rar (264.71 KB)

TOP

        ÀR«ä¦Û¦b : ¦³´¼¼z¤~¯à¤À¿ëµ½´c¨¸¥¿¡F¦³Á¾µê¤~¯à«Ø¥ß¬üº¡¤H¥Í¡C
ªð¦^¦Cªí ¤W¤@¥DÃD