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

[µo°Ý] ¸ê®Æ¤À©î°ÝÃD¡C

[µo°Ý] ¸ê®Æ¤À©î°ÝÃD¡C

¥»©«³Ì«á¥Ñ stephenlee ©ó 2021-1-23 11:34 ½s¿è

½Ð°Ý¦U¦ì°ª¤â,¦p¦ó¥ÎVBA °µ¥H¤U­n¨D,«D±`·PÁÂ

A¦ÜF ¬O¸ê®Æ¨Ó·½, H¦ÜN Äæ¬O§Ú°µ¨Ò¤l»¡©úªº¸ê®Æ, ¥­®É¤£·|¦s¦b¦bExcel ¤º, ¥u¦³AÄæ¦ÜFÄæ¸ê®Æ¦Ó¤w, ¦P®É¸ê®Æ¦³®É¦³¦h¦³¤Ö,AÄæ ¬°ªÅ¥Õ¡C
·í¤¤BÄæ©MFÄæ§Ú­n¹ïÀ³¶i¦æ¤À©î¼Æ¶q,¨Ò¦p¦pªG¸Ó¦æªºITEM ¬°SC1 , «h DÄæQTY ¨º­n¤À©î¼Æ¶q¬° ­n¨Dªº¼Æ¶q, ¨Ò¦pIIÄæ¹ïÀ³ªº©î¼Æ­n¨D¬°900
¨ºD2 «K­n¤À©î900¥X¨Ó,°£¤FQTY­n¤À©î¼Æ¶q¥~,¨ä¥L¸ê®Æ¤£ÅÜ.¦ýD2¦]¬°¦h©ó900, ©Ò¥H·s¼W¦æ¼Æ¥h¤À©î¼Æ¶q¥X¨Ó,¥t¥~¤]­n¹ïÀ³ ¤ÀÃþ KÄ檺¸ê®Æ, ¦pªG FÄ檺¤ÀÃþ¬O3ªº¸Ü
­n¦Û°ÊÀ´¥Î§Ú¨Ò¤l©Ò¥Ü,À´¤À¤T­Ó²Õ¦X¥h¦X¦¨DÄæQTYªº¼Æ¶q

¨Ò¦p F2= 3  ­Ó¤ÀÃþ  §Y¬O = 3­Ó²Õ¦X ¨C­Ó²Õ¦X­n¤À©î²Õ¦X¦¨D2 ªº¼Æ¶q

·í¤À©î¼Æ¶q«á,¦Û°Ê¦bA Äæ "Page" ¶ñ¤W 1,2 , ©ÎªÌ 3,4 , ©ÎªÌ5 ©ÎªÌSupport³o¼Ë¡C


¸ê®Æ¨Ó·½¤£ÅÜ, ·í§Ú°õ¦æVBA «á,¥L·|±N¹Bºâµ²ªG¥H·s¼W¤@±i¤u§@ªíÅã¥Üµ²ªG,¨Ò¦pSheet2 ³o¼Ë¡C

¨C¦¸·í§Ú±N¸ê®Æ½Æ»s¦ÜSheet1 ªºAÄæ¦ÜFÄæ«á, °õ¦æVBA «h¨C¦¸³£·s¼W¤@±i¤u§@ªíÅã¥Üµ²ªG¥X¨Ó¡C


°õ¦æVBA«á¥H¶K¤W­Èªº¤èªk·s¼W¤u§@ªí,«h¤£·|±N¸ê®Æ¨Ó·½ªº®æ¦¡³£½Æ»s¹L¥h,¨Ò¦p¦r«¬¤Î¦rÅé¤j¤p³£¤£­n¸ò¹L¥h¡C



¸ê®Æ¨Ó·½:




°õ¦æ«áªºµ²ªG:




¤ÀÃþ­n¨D.zip (9.12 KB)

¥»©«³Ì«á¥Ñ Andy2483 ©ó 2023-11-21 10:04 ½s¿è

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


    ÁÂÁ½׾Â,ÁÂÁ«e½ú«ü¾É
«á¾ÇÂǦ¹©«¾Ç²ß«e½úªº¤è®×,¥H¤U¬O¤ß±oµù¸Ñ,½Ð«e½ú¦A«ü¾É

Sub TEST_A01()
Dim Arr, Brr, i&, V1&, V2&, N&, j%, k%, x%
'¡ô«Å§iÅܼÆ:(Arr, Brr)³q¥Î«¬,(i,V1,V2,N)ªø¾ã¼Æ,(j,k,x)µu¾ã¼Æ
Arr = Sheets("Sheet1").UsedRange
'¡ô¥OArrÅܼƬO¤Gºû°}¦C,¥HÀx¦s®æ­È±a¤J°}¦C¤¤
ReDim Brr(1 To 20000, 1 To 6)
'¡ô«Å§iBrrÅܼƬO ¤GºûªÅ°}¦C,Áa¦V1~20000,¾î¦V1~6
For x = 1 To 6: Brr(1, x) = Arr(1, x): Next
'¡ô³]¶¶°j°é!x±q1~6,±NArr°}¦C²Ä1¦C¸ê®Æ±a¤J Brr°}¦C²Ä1¦C¤¤
For i = 2 To UBound(Arr)
'¡ô³]¶¶°j°é!i±q2¨ì Arr°}¦CÁa¦V³Ì¤j¯Á¤Þ¦C¸¹
    V1 = Int((Arr(i, 4) - 1) / Arr(i, 9))
    '¡ô¥OV1ÅܼƬO (i°j°é¦C4ÄæArr°}¦C­È-1)°£¥H i°j°é¦C9ÄæArr°}¦C­È,
    '³Ì«á¥h°£¤p¼Æªº¾ã¼Æ

    V2 = Arr(i, 4) - V1 * Arr(i, 9)
    '¡ô¥OV2ÅܼƬO i°j°é¦C4ÄæArr°}¦C­È-(V1ÅܼÆ*i°j°é¦C9ÄæArr°}¦C­È)
    For j = 12 To UBound(Arr, 2)
    '¡ô³]¶¶°j°é!j±q12¨ì Arr°}¦C¾î¦V³Ì¤j¯Á¤ÞÄ渹
        If Arr(i, j) = "" Then GoTo j01
        '¡ô¦pªGi°j°é¦Cj°j°éÄæArr°}¦C­È¬OªÅ¦r¤¸?
        'True´N¸õ¨ì¼Ð¥Üj01¦ì¸mÄ~Äò°õ¦æ

        For k = 1 To V1 + 1
        '¡ô³]¶¶°j°é!k±q1 ¨ì(V1ÅܼÆ+1)
            N = N + 1
            '¡ô¥ONÅܼƲ֥[1
            For x = 2 To 6: Brr(N + 1, x) = Arr(i, x): Next
            '¡ô±NArr°}¦Ci°j°é¦C(2~6)Äæ¸ê®Æ±a¤J Brr°}¦C¤U¤èªÅ¥Õ¦C
            Brr(N + 1, 1) = Arr(i, j)
            '¡ô¥O(N+1)¦C²Ä1ÄæBrr°}¦C­È¬O i°j°é¦Cj°j°éÄæArr°}¦C­È
            Brr(N + 1, 4) = IIf(k > V1, V2, Arr(i, 9))
            '¡ô¥O(N+1)¦C²Ä4ÄæBrr°}¦C­È¬O IIF()¦^¶Ç­È:
            '¦pªGkÅܼƤj©óV1ÅܼÆ,¦^¶ÇV2ÅܼÆ,
            '§_«h¦^¶Ç i°j°é¦C9ÄæArr°}¦C­È

        Next k
j01: Next j
Next i
With Sheets.Add
'¡ô¥H¤U¬OÃö©ó ·s¼W¤@­Ó¤u§@ªí«áªºµ{§Ç
     .[A1].Resize(N + 1, 6) = Brr
     '¡ô¥O¸Ó·sªí[A1]ÂX®i¦V¤U(N+1)¦C,¦V¥kÂX®i6ÄæÀx¦s®æ­È¥HBrr°}¦C±a¤J
     .Name = Format(Now, "yyyymmdd-hhmmss")
     '¡ô¥O¸Ó·sªíªí¦W¬O·í¤U®É¶¡¸g®æ¦¡¤Æ¬°«ü©w¤å¦r®æ¦¡ªº¦r¦ê
End With
End Sub
'=================================================
'¥H¤U¬O¦r¨å,Do Untilªº½m²ß,½Ð«e½ú¦A«ü¾É
Option Explicit
Sub TEST()
Dim Brr, Crr, Arr, V&, V2&, Z, i&, j%, R&, c%, T$
Set Z = CreateObject("Scripting.Dictionary")
Brr = Intersect(Sheet2.UsedRange, [H:IV])
For i = 2 To UBound(Brr): Z(Brr(i, 1)) = i: Next
Crr = Range([F1], [B65536].End(3)(1, 0))
ReDim Arr(20000, 1 To 6)
For j = 1 To 6: Arr(0, j) = Crr(1, j): Next
For i = 2 To UBound(Crr)
   T = Crr(i, 2): Z(T & "qty") = Val(Crr(i, 4))
   V2 = Brr(Z(T), 2): c = 0
   Do Until c = Brr(Z(T), 4)
      V = Z(T & "qty")
      Do Until V < 0
         R = R + 1
         For j = 2 To 6: Arr(R, j) = Crr(i, j): Next
         Arr(R, 1) = Brr(Z(T), 5 + c)
         Arr(R, 4) = IIf(V - V2 > 0, V2, V)
         V = V - V2
      Loop
      c = c + 1
   Loop
Next
With Sheets.Add
   .[A1].Resize(R + 1, 6) = Arr
   .Name = Format(Now, "yyyymmdd-hhmmss")
End With
End Sub
¥Î¦æ°Ê¸Ë¸mÂsÄý½×¾Â¾Ç²ß«Ü¤è«K,ÁÂÁ½׾¸gÀç¹Î¶¤
½Ð¤j®a¤@°_¤W½×¾Â¨Ó¥æ¬y

TOP

¦^´_ 5# stephenlee

¤£ ¬O§Ú¦b³Â·Ð§A  ¬O§Ú­É§AªºÃD¥Ø¨Ó¾Ç²ß ®ö¶O¤F§AÄ_¶Qªº®É¶¡ §Ú·P¨ì©êºp ÁÂÁ§AÀ°§Ú´ú¸Õ ·P®¦

TOP

¦^´_  stephenlee

°Ñ¦Ò¬Ý¬Ý:
­ã´£³¡ªL µoªí©ó 2021-1-26 15:11



    §¹¥þ²Å¦X­n¨D¤º®e,¤£¦n·N«ä¤@ª½³Â·Ð§A¡C
«D±`·PÁ»դU¤@ª½À°¦£,¦Ó¥B«D±`§Ö¦aÀ°¤F§Ú¸Ñ¨M°ÝÃD,À°§Ú¸`¬Ù¤F«Ü¦h®É¶¡¡C¦A¦¸·PÁ¡C

TOP

¦^´_  stephenlee


item ¥u¦³³o¤TºØ???
¦Ó¤ÀÃþ³Ì¦h¬O3???

¨ä¹ê¨Æ¥ý¦bH:N¿é¤J­n¤À©îªº¸ê®Æ´N¥i¥H?  ...
­ã´£³¡ªL µoªí©ó 2021-1-26 14:45



    ¬Oªº,¥u¦³¤T­ÓITEM, ¦A¦¸·PÁ­ã¤j,¡C

TOP

¦^´_ 4# stephenlee

°Ñ¦Ò¬Ý¬Ý:
Xl0000051-02.rar (16.26 KB)

TOP

¦^´_ 4# stephenlee


item ¥u¦³³o¤TºØ???
¦Ó¤ÀÃþ³Ì¦h¬O3???

¨ä¹ê¨Æ¥ý¦bH:N¿é¤J­n¤À©îªº¸ê®Æ´N¥i¥H? ¨S¦³ªº¸ê®Æ¥¦¤]¤£·|¶]¥X¨Ó

TOP

¦^´_  stephenlee
°Ñ¦Ò¤F ·Ç¤jªº¼gªk  ¶¶«K½m²ß ¦³ªÅªº¸Ü¤]¶¶«KÀ°§Ú¬Ý¬Ý ¬O§_¥¿±` ·PÁÂ
°a¤ªºµ µoªí©ó 2021-1-24 18:54



    ÁÂÁ¤j¤j²Ó¤ßÀ°¦£,«D±`·PÁÂ, ¸g´ú¸Õ³£¬Ookªº,¤£¹L§Ú»Ý­n¦A§ó·s¤º®e,©Ò¥H´N¤£¦n·N«ä¦A³Â·Ð§A¤F¡CÁÂÁÂ

TOP

Sub TEST_A01()
Dim Arr, Brr, i&, j%, k%, X%, V1&, V2&, N&
Arr = Sheets("Sheet1").UsedRange
ReDim  ...
­ã´£³¡ªL µoªí©ó 2021-1-23 17:38



   ÁÂÁ­ã¤jÀ°¦£,¸g´ú¸Õ¬O§¹¥þOKªº¡C

¤£¹L¤£¦n·N«ä.§Ú§Ñ¤F»¡ H¨ìN¨º, ªº²Õ¦X¤£¬O©T©wªº

¨Ò¦p  SC1 ©î¼Æ¤@©w¬O 900  , SC2 ©î¼Æ¤@©w¬O900,SC3 ©î¼Æ ¤@©w¬O 1800, ¦ý¥Lªº²Õ¦X¤£¬O SC1 Âê©w¤F ¤ÀÃþ ²Ä 3 , ¦ÓSC2 ¤£¬OÂê©w¤F¬O²Ä2, ¤£¹LSC3 ´N¥²©w¬O1 ¡C

¨Ò¦p SC1 ªº¤ÀÃþ¥i¥H¥h 2 , ´N¬O 1,2 ©M 3.4 ¡C ¦ÓSC2 ªº¤ÀÃþ¥i¥H¥h 3, ´N¬O 1,2 + 3,4 +5


¦ÓSC3 «h¤@ª½¤£ÅÜ¡C

¦ÓSC2©MSC3 ¥¼¥²¨C¦¸³£¦³¸ê®Æ, ©Ò¥H¸ò©î¼Æ«á¤]­n¸ò¤ÀÃþ¨Ó·s¼W¦æ¼Æ¡C

¦Ó°µªk³£¬O¸ò¤§«e­n¨D¤@¼Ë,¶ñ¤W¸ê®Æ«á,®Ú¾Ú¼Æ¶q¤Î¤ÀÃþ°õ¦æ¦A¥H·s¤@­Ó¤u§@ªíÅã¥Ü¡C ¥u¤£¹L¬O«ö·Ó¨C¦¸©Ò¶ñ¤WªºItem ©M¤ÀÃþ¨Ó§PÂ_°µ¾ã²z¡C

¯S§O¤£¦n·N«ä,¦A³Â·Ð§A¡C «D±`·P¿E§Aªº²Ó¤ßÀ°¦£¡CÁÂÁÂ


¤ÀÃþ­n¨D §ó·s.zip (10.78 KB)

TOP

¥»©«³Ì«á¥Ñ °a¤ªºµ ©ó 2021-1-24 18:56 ½s¿è

¦^´_ 1# stephenlee
°Ñ¦Ò¤F ·Ç¤jªº¼gªk  ¶¶«K½m²ß ¦³ªÅªº¸Ü¤]¶¶«KÀ°§Ú¬Ý¬Ý ¬O§_¥¿±` ·PÁÂ
  1. Public Sub ¸ê®Æ¤À©î½m²ß()
  2. Application.ScreenUpdating = False
  3. Arr = [A1].CurrentRegion
  4. Ar = [{900, "1,2", "3,4", "5"; 900, "1,2", "3,4","-"; 1800, "Support","-","-"}]

  5. Sheets.Add(After:=Sheets(1)).Name = "µ²ªG" & Format(Now, "-YYYY-MM-DD")
  6. For Y = 1 To UBound(Arr, 2): Cells(1, Y) = Arr(1, Y): Next Y
  7. For X = 1 To UBound(Ar)
  8.     A = Int(Arr(2 + k, 4) / Ar(X, 1)) + 1
  9.     C = Arr(2 + k, 4) - (A - 1) * Ar(X, 1)
  10.     For i = 2 To UBound(Ar, 2)
  11.         If Ar(X, i) <> "-" Then
  12.         For Y = 1 To A
  13.             If u < A Then u = u + 1
  14.             E = IIf(u = A, C, Ar(X, 1))
  15.             Cells(2 + G, 1) = Ar(X, i)
  16.             Cells(2 + G, 2) = Arr(2 + k, 2)
  17.             Cells(2 + G, 3) = Arr(2 + k, 3)
  18.             Cells(2 + G, 4) = E
  19.             Cells(2 + G, 5) = Arr(2 + k, 5)
  20.             Cells(2 + G, 6) = Arr(2 + k, 6)
  21.             G = G + 1
  22.         Next Y
  23.         End If
  24.     u = 0
  25.     Next i
  26. k = k + 1
  27. Next X
  28. Application.ScreenUpdating = True
  29. End Sub
½Æ»s¥N½X

TOP

        ÀR«ä¦Û¦b : ¬O«D·í±Ð¨|¡AÆg¬ü§@ĵ±§¡C
ªð¦^¦Cªí ¤W¤@¥DÃD