- ©«¤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 ©ó 2018-8-31 08:35 ½s¿è
¦^´_ 22# s7659109
¾A¥Î ¨D¨C¤ë³Ì¤j»P³Ì¤pNO¤§pºâ0822¶i¶¥ª©.xlsm
¸Õ¸Õ¬Ý- Option Explicit
- Sub Ex()
- Dim AR(), Rng As Range, i As Integer, ii As Integer, iii As Integer, xYear As String, AB As Variant
- '**¤u§@ªí1¤W¦³¤@¨Ç¨ç¼Æ°õ¦æµ{¦¡®É·|«·spºâ,¼vÅT°õ¦æ³t«×.**
- Application.Calculation = xlManual '³]©w¥Nªípºâ¼Ò¦¡¬°¤â°Ê
- With ¤u§@ªí1.Range("A1").CurrentRegion
- '**Range.CurrentRegion ÄÝ©Ê ¶Ç¦^ Range ª«¥ó¡A¸Óª«¥ó¥Nªí¥Ø«eªº°Ï°ì¡C¥Ø«e°Ï°ì¬O«ü¥H¥ô·NªÅ¥Õ¦C¤ÎªÅ¥ÕÄ檺²Õ¦X¬°Ãä¬Éªº½d³ò¡C°ßŪªº
- .Sort key1:=.Cells(1), key2:=.Cells(1, 2), key3:=.Cells(1, 3), Header:=xlYes
- '** ¸ê®Æ±Æ§Ç
- End With
- With ¤u§@ªí2
- .UsedRange.Clear '¤£¥²§@¾ãÓ¤u§@ªíªº²M°£
- '**Worksheet.UsedRange ÄÝ©Ê ·|¶Ç¦^ Range ª«¥ó¡A¦¹ª«¥ó¥Nªí«ü©w¤u§@ªí¤Wªº¤w¥Î½d³ò¡C°ßŪªº¡C
-
- '**¿z¿ï¥X ¤u§@ªí1.Range("Al:A")¤W¤£«½ÆªºITEM¨ì.Range("A1")¤U***
- ¤u§@ªí1.Range("A1").CurrentRegion.Columns(1).AdvancedFilter xlFilterCopy, "", .Range("A1"), True
- '**Range.AdvancedFilter ¤èªk ®Ú¾Ú·Ç«h½d³ò¡A±q²M³æ¤¤¿z¿ï©Î½Æ»s¸ê®Æ¡C¦pªGªì©l¿ï¾Ü¬°³æ¤@Àx¦s®æ¡A«h·|¨Ï¥ÎÀx¦s®æªº¥Ø«e°Ï°ì¡C
-
- .Range("C1").Resize(, 2) = Array(¤u§@ªí1.[A1], ¤u§@ªí1.[D1])
- .Range("C3").Resize(, 3) = Array(¤u§@ªí1.[A1], ¤u§@ªí1.[B1], ¤u§@ªí1.[D1])
- Set Rng = .[a2]
- xYear = Mid(¤u§@ªí1.Range("D2"), 1, Len(¤u§@ªí1.Range("D2")) - 4) '¦~¥÷
- ReDim AR(1 To Rng.End(xlDown).Row, 1 To 49) '**ReDim ³¯z¦¡ ¦bµ{§Ç¼h¦¸¤¤¥Î¨Ó«·s°t¸m°ÊºA°}¦CÅܼƪºÀx¦sªÅ¶¡¡C
- Do
- AR(Rng.Row, 1) = Rng '¾É¤JITEM **.Range("A1")¤U¤£«½ÆªºITEM**
- For i = 1 To 12
- '***¿z¿ï·Ç«h****
- .Range("C2") = Rng 'ITEM
- .Range("D2") = xYear & Format(i, "00") & "*" '¦~¥÷&¤ë¥÷
- '** ¶i¶¥¿z¿ï**
- ¤u§@ªí1.Range("A1").CurrentRegion.AdvancedFilter Action:=xlFilterCopy, CriteriaRange:=.Range("C1").Resize(2, 2), CopyToRange:=.Range("C3").Resize(, 3), Unique:=True
- If .Range("d4") <> "" Then '¿z¿ï¥X¸ê®Æ
- AR(Rng.Row, ((i - 1) * 4) + 2) = .Range("d4") '³Ì¤p
- If .Range("d4").End(xlDown).Row = Rows.Count Then '¸ê®Æ¥u¦³¤@µ§
- AR(Rng.Row, ((i - 1) * 4) + 3) = .Range("d4") '³Ì¤j
- AR(Rng.Row, ((i - 1) * 4) + 5) = 1 'p¼Æ
- Else
- For iii = .Range("d4") + 1 To .Range("d4").End(xlDown) - 1 '²Ä¤G³Ì¤pÈ TO ²Ä¤G³Ì¤jȪº°j°é
- AB = Application.Match(Format(iii, "00000"), .Range(.Range("d4"), .Range("d4").End(xlDown)), 0)
- If IsError(AB) Then AR(Rng.Row, ((i - 1) * 4) + 4) = IIf(AR(Rng.Row, ((i - 1) * 4) + 4) <> "", AR(Rng.Row, ((i - 1) * 4) + 4) & ",", "'") & Format(iii, "00000")
- 'AB¬O¿ù»~È-> iii¬° "01¤¤¶¡º|±¼¸¹½X"
- Next
- AR(Rng.Row, ((i - 1) * 4) + 3) = .Range("d4").End(xlDown) '³Ì¤j
- AR(Rng.Row, ((i - 1) * 4) + 5) = .Range("d4").End(xlDown).Row - 3 'p¼Æ
- End If
- End If
- Next
- '**Àˬd¤ë¥÷¶¡ªº¿òº|**
- For ii = 3 To UBound(AR, 2) - 4 Step 4
- AB = AR(Rng.Row, ii)
- Do While AB + 1 < Val(AR(Rng.Row, ii + 3))
- AR(Rng.Row, ii + 1) = IIf(AR(Rng.Row, ii + 1) <> "", AR(Rng.Row, ii + 1) & ",", "'") & Format(AB + 1, "00000")
- AB = AB + 1
- Loop
- Next
- Set Rng = Rng.Offset(1) '¤U¤@Ó .Range("A1")¤U¤£«½ÆªºITEM
- Loop Until Rng = "" 'Until->µ²§ô°j°éªº±ø¥ó
- .UsedRange.Clear
- With .Range("A1")
- .Value = "¤ë¥÷"
- AR(1, 1) = "¶µ¥Ø"
- For i = 1 To 12
- With .Cells(1, (i - 1) * 4 + 2).Resize(, 4)
- .Merge
- .NumberFormatLocal = "00"
- .HorizontalAlignment = xlCenter
- .Value = i
- End With
- For ii = 0 To 3
- AR(1, ii + ((i - 1) * 4) + 2) = Array("³Ì¤p", "³Ì¤j", "01¤¤¶¡º|±¼¸¹½X", "p¼Æ")(ii)
- If ii <= 1 Then
- .Cells(3, ii + ((i - 1) * 4) + 2).Resize(Rng.Row - 2).NumberFormatLocal = "00000"
- End If
- Next
- Next
- .Offset(1).Resize(UBound(AR), UBound(AR, 2)) = AR
- End With
- End With
- Application.Calculation = xlCalculationAutomatic 'pºâ¼Ò¦¡¬°¦Û°Ê
- End Sub
½Æ»s¥N½X |
|