- ©«¤l
- 1446
- ¥DÃD
- 40
- ºëµØ
- 0
- ¿n¤À
- 1470
- ÂI¦W
- 0
- §@·~¨t²Î
- Windows 7
- ³nÅ骩¥»
- Excel 2010 & 2016
- ¾\ŪÅv
- 50
- ©Ê§O
- ¨k
- ¨Ó¦Û
- ¥xÆW
- µù¥U®É¶¡
- 2020-7-15
- ³Ì«áµn¿ý
- 2024-10-21
|
¥»©«³Ì«á¥Ñ Andy2483 ©ó 2023-2-10 14:42 ½s¿è
¦^´_ 15# ymes
ÁÂÁ«e½ú,«á¾ÇÀrÆj§Þ½a¤F,½Ð«e½úÌ«ü¾É
¤£ª¾«e½ú§ï°Ê¦h¤Öµ{¦¡½X?
½Ð±N¤U¦C¬õ¦r·s¼W©Î¨ú¥N, ©Î ¤W¶Ç«e½ú³Ì·s½d¨Ò
Option Explicit
Dim ²Õªí®æ As Range, R&, C%
Sub ¶}©l¤À²Õ()
Dim Drr, Brr, Crr, Y, ¶Ã¼Æ&, ¤H¼Æ&, ¹D¼Æ&, ²Õ¼Æ&, °õ¦æ¼Æ&, ¶]¹D¼Æ&, i&
Dim ¶µ¥Ø$, Arr(1 To 1000, 1 To 3), n&, ²Õ§O, xR As Range
¶µ¥Ø = Split(ActiveSheet.Name, "(")(0)
¶]¹D¼Æ = [A2].End(xlDown).Row - 2
Drr = Range([³ø¦Wªí!C2], [³ø¦Wªí!A65536].End(3))
For i = 1 To UBound(Drr)
If Drr(i, 3) Like ¶µ¥Ø & "*" Then
n = n + 1
Arr(n, 1) = Drr(i, 1): Arr(n, 2) = Drr(i, 2): Arr(n, 3) = Drr(i, 3)
End If
Next
If n = 0 Then
MsgBox "¨S¦³¦W³æ!µLªk°õ¦æ": Exit Sub
End If
If ¶]¹D¼Æ < 1 Then
MsgBox "¶]¹D¼Æ¤£²Å¦X³W«h!µLªk°õ¦æ": Exit Sub
End If
Call ²M°£: [L1].Resize(n, 3) = Arr
¤H¼Æ = n: ReDim Brr(¶]¹D¼Æ - 1, 1)
Head:
Set Y = CreateObject("Scripting.Dictionary")
Do While °õ¦æ¼Æ < ¤H¼Æ
Randomize: ¶Ã¼Æ = Rnd() * 10000 Mod ¤H¼Æ + 1
If Y.Exists(¶Ã¼Æ) = Empty Then
°õ¦æ¼Æ = °õ¦æ¼Æ + 1
Y(¶Ã¼Æ) = ""
¹D¼Æ = °õ¦æ¼Æ Mod ¶]¹D¼Æ
Y(Arr(¶Ã¼Æ, 1) & "|" & ¹D¼Æ) = ""
²Õ¼Æ = IIf(¹D¼Æ, °õ¦æ¼Æ \ ¶]¹D¼Æ + 1, °õ¦æ¼Æ \ ¶]¹D¼Æ)
Y(Arr(¶Ã¼Æ, 1) & "/" & ²Õ¼Æ) = ""
Crr = Y(²Õ¼Æ & "/²Õ")
If Not IsArray(Crr) Then Crr = Brr
¹D¼Æ = IIf(¹D¼Æ, ¹D¼Æ, ¶]¹D¼Æ)
Crr(¹D¼Æ - 1, 0) = Arr(¶Ã¼Æ, 1): Crr(¹D¼Æ - 1, 1) = Arr(¶Ã¼Æ, 2)
Y(²Õ¼Æ & "/²Õ") = Crr
End If
If (Y.Count - ²Õ¼Æ) Mod °õ¦æ¼Æ Then ²Õ¼Æ = 0: °õ¦æ¼Æ = 0: GoTo Head
Loop
'For i = 1 To ²Õ¼Æ - 1: ²Õªí®æ.Copy Cells(i * (R + 1) + 1, 1): Next '³o¦æÂI±¼,·s¼W¤U¦C¬õ¦r
Dim S$, T&
For i = 1 To ²Õ¼Æ - 1
²Õªí®æ.Copy Cells(i * (R + 1) + 1, 1)
T = 3 + ((R + 1) * i)
S = "=IF(F" & T & "<>0,RANK(F" & T & ",$F$" & T & ":$F$" & T + ¶]¹D¼Æ - 1 & ",1),"""")"
Cells(i * (R + 1) + 1, 1).Item(3, 7).Resize(¶]¹D¼Æ, 1) = S
Next
For i = 1 To ²Õ¼Æ
²Õ§O = "(²Ä" & Application.Text(i, "[DBNum1]0") & "²Õ)"
Set xR = [B3].Item((i - 1) * (¶]¹D¼Æ + 3) + 1, 1)
xR.Resize(¶]¹D¼Æ, 2) = Y(i & "/²Õ")
Set xR = xR.Item(-1, 0)
xR.Value = Split(xR.Value, "(")(0) & ²Õ§O
Next
End Sub
Sub ²M°£()
Dim uR&
R = [A2].End(xlDown).Row
C = [A2].End(xlToRight).Column
uR = ActiveSheet.UsedRange.Rows.Count
[L:N].ClearContents
[A2].End(xlDown).Item(2, 1).Resize(uR - R, C).Clear
[B3].Resize(R - 2, 2).ClearContents
'·s¼W¤U¦C¬õ¦r
[F3].Resize(R - 2, 1).ClearContents
[G3].Resize(R - 2, 1) = "=IF(F3<>0,RANK(F3,$F$3:$F$" & R & ",1),"""")"
Set ²Õªí®æ = Range([A1], Cells(R, C))
End Sub |
|