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

[µo°Ý] vlookup¦X¦}ªº¸ê®Æ

¥»©«³Ì«á¥Ñ Andy2483 ©ó 2023-12-26 13:50 ½s¿è

ÁÂÁ½׾Â,ÁÂÁ¦U¦ì«e½ú
«á¾ÇÂǦ¹©«½m²ß°}¦C»P¦r¨å,½m²ß¤è®×¦p¤U,½Ð¦U¦ì«e½ú«ü±Ð
°õ¦æ«e:


°õ¦æµ²ªG:


Option Explicit
Sub TEST_A()
Dim ¸ê®Æ°}¦C, ªÅ°}¦C(1 To 1000, 1 To 2), ¦r¨åÃöÁä¦r, ¦r¨å, ³f¬[§Ç¸¹, i&, µ²ªG°}¦C
Dim µ²ªG°_©l®æ As Range, µ²ªG°}¦C¦C¸¹&
Set ¦r¨å = CreateObject("Scripting.Dictionary")
ActiveSheet.UsedRange.Offset(, 10).EntireColumn.Delete
Set µ²ªG°_©l®æ = [K1]
¸ê®Æ°}¦C = Range([E2], [D65536].End(xlUp)(2, 0))
For i = 1 To UBound(¸ê®Æ°}¦C) - 1
   If ³f¬[§Ç¸¹ <> ¸ê®Æ°}¦C(i, 1) Then ³f¬[§Ç¸¹ = ¸ê®Æ°}¦C(i, 1)
   If ¸ê®Æ°}¦C(i + 1, 1) = "" Then ¸ê®Æ°}¦C(i + 1, 1) = ³f¬[§Ç¸¹
   ³f¬[§Ç¸¹ = ¸ê®Æ°}¦C(i, 1): µ²ªG°}¦C = ¦r¨å(³f¬[§Ç¸¹): µ²ªG°}¦C¦C¸¹ = ¦r¨å(³f¬[§Ç¸¹ & "/r")
   If Not IsArray(µ²ªG°}¦C) Then µ²ªG°}¦C = ªÅ°}¦C
   µ²ªG°}¦C¦C¸¹ = µ²ªG°}¦C¦C¸¹ + 1
   µ²ªG°}¦C(µ²ªG°}¦C¦C¸¹, 1) = ¸ê®Æ°}¦C(i, 2): µ²ªG°}¦C(µ²ªG°}¦C¦C¸¹, 2) = ¸ê®Æ°}¦C(i, 3)
   ¦r¨å(³f¬[§Ç¸¹ & "/r") = µ²ªG°}¦C¦C¸¹: ¦r¨å(³f¬[§Ç¸¹) = µ²ªG°}¦C
Next
For Each ¦r¨åÃöÁä¦r In ¦r¨å.keys
   If Not IsArray(¦r¨å(¦r¨åÃöÁä¦r)) Then GoTo V01
   µ²ªG°_©l®æ = ¦r¨åÃöÁä¦r
   With µ²ªG°_©l®æ(2, 1).Resize(¦r¨å(¦r¨åÃöÁä¦r & "/r"), 2)
      .Value = ¦r¨å(¦r¨åÃöÁä¦r)
      .Borders.LineStyle = 1
      .Cells(.Count + 1) = "Total"
      .Cells(.Count + 2) = "=SUM(" & .Columns(2).Address & ")"
   End With
   Set µ²ªG°_©l®æ = µ²ªG°_©l®æ(, 4)
V01: Next
End Sub
¥Î¦æ°Ê¸Ë¸mÂsÄý½×¾Â¾Ç²ß«Ü¤è«K,ÁÂÁ½׾¸gÀç¹Î¶¤
½Ð¤j®a¤@°_¤W½×¾Â¨Ó¥æ¬y

TOP

GPT4
¦b±z´£¨Ñªº¹Ï¤ù¤¤¡A¥ª°¼¬O¤@­Ó¸ê®Æ¦Cªí¡A¥k°¼¬O¤@­Ó¶×Á`µ²ªG¡C³o­Ó¦Cªí¦ü¥G¬O¥Î©ó°l踪®w¦s©Î³f¬[¤Wªºª««~¡C³f¬[§Ç¸¹¦b¬Y¨Ç¦æ¬O¦X¨Öªº¡A¥B¦X¨Öªº¦æ¼Æ¤£©T©w¡C±z§Æ±æ¯à°÷¹³¥kÃä®i¥Üªº¨º¼Ë¡A³q¹L¿é¤J³f¬[§Ç¸¹¡Aª½±µ±N¬ÛÃö¸ê®ÆÂಾ¨ì¥k°¼¡C

´£¨Ñªº¥N½X¬O¤@­Ó Excel §»¡A¥Î©ó³B²z³oºØÃþ«¬ªº¸ê®ÆÂಾ¡C¥N½X¶i¦æ¤F¦p¤U¾Þ§@¡G

½T©w¼Æ¾Ú½d³ò¡C
²M°£¥Ø¼Ð½d³ò¡]K2:U1000¡^ªº¤º®e¡C
¹M¾ú¯S©wªº¦C¡]K1, N1, Q1, T1¡^¡A³o¨Ç¦C¦ü¥G¬O¥Î¨Ó«ü©w¤£¦Pªº³f¬[§Ç¸¹¡C
¹ï©ó¨C­Ó«ü©wªº³f¬[§Ç¸¹¡A¥N½X´M§ä¥ª°¼¦Cªí¤¤©Ò¦³¤Ç°tªº¦æ¡C
±N¤Ç°t¦æ¤¤ªº¸ê®Æ½Æ»s¨ì¥k°¼ªº¬ÛÀ³¦ì¸m¡C
­pºâ¨Ã²K¥[Á`¼Æ¨ì³Ì«á¡C
ª`ÄÀ±zªº¥N½X¡A¥H«K©ó²z¸Ñ¨C¤@³¡¤Àªº¥\¯à¡G

vb
Copy code
Sub test()
    ' Àò¨ú³Ì«á¤@¦æªº¦æ¸¹
    r = Cells(Rows.Count, 1).End(xlUp).Row
    ' ²M°£K2¨ìU1000½d³ò¤ºªº©Ò¦³¤º®e
    Range("k2:u1000").ClearContents
   
    ' ¹M¾úK1, N1, Q1, T1³o¥|¦Cªº³æ¤¸®æ
    For Each Z In Range("K1,N1,Q1,T1")
        t5 = 0: t4 = 0 ' ªì©l¤ÆÅܶq
        ' ¦pªG·í«e³æ¤¸®æ¦³­È
        If Z.Value <> "" Then
            ' ¹M¾ú2¨ì³Ì«á¤@¦æ
            For i = 2 To r
                ' ¦pªG·í«e¦Cªº­È»PC¦Cªº­È¬Û¦P¡]¤£°Ï¤À¤j¤p¼g¡^
                If UCase(Z.Value) = UCase(Cells(i, 3).Value) Then
                    ' ¹M¾ú¦X¨Ö°Ï°ìªº¨C¤@¦æ
                    For j = i To Cells(i, 3).MergeArea.Count + i - 1
                        t4 = t4 & "¡¶" & Cells(j, 4)
                        t5 = t5 & "¡¶" & Cells(j, 5)
                        tsum = tsum + Cells(j, 5)
                    Next
                End If
            Next
            
            ' ¤Á³Î¦r²Å¦êÀò¨ú¸ê®Æ¼Æ²Õ
            a4 = Split(Mid(t4 & "¡¶Total", 3, 9999), "¡¶")
            a5 = Split(Mid(t5 & "¡¶" & tsum, 3, 9999), "¡¶")
            
            ' ¦pªG¼Æ²Õ¦³¸ê®Æ
            If UBound(a4) > 0 Then
                ' ±N¼Æ¾Ú¶ñ¥R¨ì«ü©wªº³æ¤¸®æ°Ï°ì
                Z.Offset(1, 0).Resize(UBound(a4) + 1, 1) = Application.Transpose(a4)
                Z.Offset(1, 1).Resize(UBound(a4) + 1, 1) = Application.Transpose(a5)
            End If
        End If
    Next
End Sub
½Ðª`·N¡A³o¬q¥N½X¬O°ò©ó°²©w³f¬[§Ç¸¹¦C¡]C¦C¡^ªº¦X¨Ö°Ï°ì¥i¥H³q¹L .MergeArea.Count ¥¿½TÀò±o¡C¥t¥~¡A³o¬q¥N½X¨Ï¥Î¤F UCase ¨ç¼Æ¨Ó¶i¦æ¤£°Ï¤À¤j¤p¼gªº¤ñ¸û¡C¦pªG±zªº³f¬[§Ç¸¹°Ï¤À¤j¤p¼g¡A«h¤£À³¨Ï¥Î UCase ¨ç¼Æ¡C

TOP

¦^´_ 9# singo1232001


    ÁÂÁ¡I¯à¤£¯à¦³ª`ÄÀ¤@¤U¡A³o¼Ë§Ú¥i¥H§ó¦n²z¸Ñ¨C¥y¥Î·N¡A¦pªG®æ¦¡©ÎªÌªí®æ¦³ÅÜ°Ê¡A¤]¥i¥H¦Û¤v°µ¥X­×§ï¡C:handshake

TOP

¦^´_ 7# 198188


    ¤§«eªº¥N½X ¬O¦bk1¥´¦r´N·|ª½±µÄ²µo¾Þ§@

­Y·Q­n¥´§¹¦A¤â°Ê°õ¦æ¥Î¦p¤U¥N½X
Sub test()
r = Cells(Rows.Count, 1).End(3).Row
Range("k2:u1000").ClearContents
For Each Z In Range("K1,N1,Q1,T1")
t5 = 0: t4 = 0
If Z.Value <> "" Then
    For i = 2 To r
    If UCase(Z.Value) = UCase(Cells(i, 3).Value) Then
        For j = i To Cells(i, 3).MergeArea.Count + i - 1
        t4 = t4 & "¡¶" & Cells(j, 4)
        t5 = t5 & "¡¶" & Cells(j, 5)
        tsum = tsum + Cells(j, 5)
        Next
    End If
    Next
   
    a4 = Split(Mid(t4 & "¡¶Total", 3, 9999), "¡¶")
    a5 = Split(Mid(t5 & "¡¶" & tsum, 3, 9999), "¡¶")
   
    If UBound(a4) > 0 Then
    Z.Offset(1, 0).Resize(UBound(a4) + 1, 1) = Application.Transpose(a4)
    Z.Offset(1, 1).Resize(UBound(a4) + 1, 1) = Application.Transpose(a5)
    End If
End If
Next

End Sub

TOP

¦^´_ 7# 198188
¦]¬°§A­ìªí®æ¬O¦b³æ¤¸®æK1,N1µ¥¦a¤è¾Þ§@....©Ò¥H¼y¤j°w¹ï§A»Ý¨D¼gªº¡A
¨Ì­ì¥»ªí®æ¶ñ¤J³f¸¹¡A·í¤u§@ªíÅܤƮɡA¤º®e´N·|ÅܰʤF....¬Ý¹Ï¤K¡C
-----------------------------------

TOP

¦^´_ 6# shuo1125


  ¦ý¬O³o¼Ë¦p¦ó¾Þ§@¡H¦p¤W¶Kªþ¥ó¡A¨S¦³¥ô¦ó¤ÏÀ³¥X¨Ó¡C

TOP

¥»©«³Ì«á¥Ñ shuo1125 ©ó 2023-12-21 11:09 ½s¿è

¦^´_ 5# 198188
§A¦n~
¦¹¬°¤u§@ªí¨Æ¥ó¤¤½s¼gªºµ{¦¡½X¡A¬G¤£·|¥X²{¦b¼Ð·Çªº¡uÀ˵ø¥¨¶°¡v¦Cªí¤¤¡C
<¦]¤£ÄÝ©ó¼Ò²Õ¡]Modules¡^>

TOP

¥»©«³Ì«á¥Ñ 198188 ©ó 2023-12-21 09:23 ½s¿è

¦^´_ 4# singo1232001
¦³ÂI©_©Ç¡A§âµ{¦¡©ñ¦b­¶­±ùØ¡A¦ý¬O¶}excel, À˵ø¥¨¶°®É¡Aª©­±¨S¦³¥ô¦ó¥¨¶°¡C

test vba.zip (82.13 KB)

TOP

¥»©«³Ì«á¥Ñ singo1232001 ©ó 2023-12-21 02:42 ½s¿è

¦^´_ 3# 198188

¥N½X»Ý©ñ¦b¤u§@ªí¼Ò²Õ  ¤£­n©ñ¦bModule1


    Dim OUT1
Private Sub Worksheet_Change(ByVal Target As Range)
If OUT1 = True Then Exit Sub
If Target.Height > 10000 Then Exit Sub
If Target.Width > 10000 Then Exit Sub
If Target.Count > 1 Then Exit Sub
If Target.Value = "" Then Exit Sub
If Target.Row > 1 Then Exit Sub
If Target.Column = 11 Then
ElseIf Target.Column = 14 Then
ElseIf Target.Column = 17 Then
ElseIf Target.Column = 20 Then
Else
Exit Sub
End If
OUT1 = True
Target.Offset(1, 0).Resize(100000, 2).ClearContents
OUT1 = False
r = Cells(Rows.Count, 1).End(3).Row
For i = 2 To r
If UCase(Target.Value) = UCase(Cells(i, 3).Value) Then
OUT1 = True
For j = i To Cells(i, 3).MergeArea.Count + i - 1
w = w + 1
Target.Offset(w, 0).Resize(1, 2).Value = Cells(j, 4).Resize(1, 2).Value
sumx = sumx + Cells(j, 5)
Next
End If
Next
If w <> 0 Then Target.Offset(w + 1, 0).Resize(1, 2) = Array("Total", sumx)
OUT1 = False
End Sub

TOP

¦^´_ 2# hcm19522


    ÁÂÁ¡A¤£¹L³o­ÓµªÀ³¥X¨Óªº®ÄªG¡A¤£¬O§Úªº°ÝÃDªº¥Øªº¡C

TOP

        ÀR«ä¦Û¦b : ¦n¨Æ­n´£±o°_¡A¬O«D­n©ñ±o¤U¡A¦¨´N§O¤H§Y¬O¦¨´N¦Û¤v¡C
ªð¦^¦Cªí ¤W¤@¥DÃD