- ©«¤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
|
¦^´_ 12# luke - Option Explicit
- Sub Ex°}¦C()
- Dim Ar1(), Ar2(), A As Range, S As Variant, xR(1 To 2)
- S = 1
- With sheet2
- For Each A In .Range(.[D2], .[D2].End(xlDown))
- ReDim Preserve Ar1(1 To S)
- ReDim Preserve Ar2(1 To S)
- Ar1(S) = A & A.Cells(1, 2)
- Ar2(S) = .Range(A.Cells(1, 3), A.Cells(1, 2).End(xlToRight)).Value
- Ar2(S) = Application.Transpose(Application.Transpose(Ar2(S)))
- S = S + 1
- Next
- End With
- With sheet1
- For Each A In .Range(.[A1], .[A1].End(xlDown))
- S = Application.Match(A & A(1, 2), Ar1, 0)
- If Not IsError(S) Then
- xR(1) = A(1, 3)
- xR(2) = A(1, 4)
- If IsNumeric(A(1, 3)) Then If A(1, 3).Value + 1 <= UBound(Ar2(S)) Then xR(1) = Ar2(S)(A(1, 3) + 1)
- If IsNumeric(A(1, 4)) Then If A(1, 4).Value + 1 <= UBound(Ar2(S)) Then xR(2) = Ar2(S)(A(1, 4) + 1)
- A.Offset(, 5).Resize(, 4) = Array(A, A(1, 2), xR(1), xR(2))
- Else
- A.Offset(, 5).Resize(, 4) = A.Resize(, 4).Value
- End If
- Next
- End With
- End Sub
- Sub Ex¦r¨åª«¥ó()
- Dim d As Object, Ar(), A As Range, C As Range, B As Range, x As String
- Set d = CreateObject("Scripting.Dictionary")
- With sheet2
- For Each A In .Range(.[D2], .[D2].End(xlDown))
- x = A & A.Cells(1, 2)
- For Each C In .Range(A.Cells(1, 3), A.Cells(1, 2).End(xlToRight))
- If d.Exists(x) Then
- Ar = d(x)
- ReDim Preserve Ar(UBound(Ar) + 1)
- Ar(UBound(Ar)) = C.Value
- d(x) = Ar
- Else
- d(x) = Array(C.Value)
- End If
- Next
- Next
- End With
- With sheet1
- For Each A In .Range(.[A1], .[A1].End(xlDown))
- If d.Exists(A & A(1, 2)) Then
- ReDim Ar(2)
- Ar(0) = d(A & A(1, 2))
- If A(1, 3) <= UBound(Ar(0)) Then Ar(1) = Ar(0)(A(1, 3)) Else Ar(1) = A(1, 3)
- If A(1, 4) <= UBound(Ar(0)) Then Ar(2) = Ar(0)(A(1, 4)) Else Ar(2) = A(1, 4)
- A.Offset(, 5).Resize(, 4) = Array(A, A(1, 2), Ar(1), Ar(2))
- Else
- A.Offset(, 5).Resize(, 4) = A.Resize(, 4).Value
- End If
- Next
- End With
- End Sub
½Æ»s¥N½X |
|