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

[µo°Ý] ¦Û°Ê¨Ì·Ó¼Æ¶q»¼¼W§Ç¸¹

[µo°Ý] ¦Û°Ê¨Ì·Ó¼Æ¶q»¼¼W§Ç¸¹

¤p§ÌVBAÁÙ°±¯d¦b¿ý»s¤Î­×§ïµ{¦¡ªº·s¤â¯Å¶¥¬q
¥H¤U¹J¨ì°ÝÃDµLªk¿ý»s¸Ñ¨MÁٽЫe½ú«ü¾É

¦pªþ¥ó TEST§Ç¸¹1.rar (21.41 KB)

½Ð°Ý­n¦p¦ó¨Ï¥ÎVBA±NM~Qªº¸ê®Æ¡A¨Ì§Ç±qC6¶}©l¡A¨Ì·Ó¾÷ºØ¡B¼Æ¶q§â"§Ç¸¹-«e"¨Ì§Ç»¼¼W¤W¥h
§¹¦¨«áSHEET2ªº¼Ë¤l ·PÁ¡C

TEST§Ç¸¹.rar (21.21 KB)

¥»©«³Ì«á¥Ñ Andy2483 ©ó 2023-6-21 16:23 ½s¿è

¦^´_ 1# abc9gad2016


    ÁÂÁ«e½úµoªí¦¹¥DÃD»P½d¨Ò
«á¾ÇÂǦ¹©«½m²ßVBA°}¦C,¾Ç²ß¤è®×¦p¤U,½Ð«e½ú°Ñ¦Ò

°õ¦æ«e:


°õ¦æµ²ªG:


Option Explicit
Sub TEST()
Dim Brr, Crr, V&, i&, R, N&, S%
Brr = Range([§Ç¸¹·s¼W!Q3], [§Ç¸¹·s¼W!M65536].End(xlUp))
ReDim Crr(1 To 60000, 1 To 11)
For i = 1 To UBound(Brr)
   S = IIf(Brr(i, 2) <= Brr(i, 3), 1, -1)
   For R = Val(Brr(i, 2)) To Val(Brr(i, 3)) Step S
      V = V + 1
      N = N + 1
      Crr(V, 1) = N
      Crr(V, 3) = Brr(i, 1)
      Crr(V, 4) = R
      Crr(V, 11) = Brr(i, 5)
   Next
   N = 0
Next
If V = 0 Then Exit Sub
Sheets("§Ç¸¹·s¼W").UsedRange.Offset(5, 0).Delete
With Sheets("§Ç¸¹·s¼W").[A6].Resize(V, 11)
   .Value = Crr
   With .Columns(6)
      .Value = "=IF(E6="""","""",RIGHT(E6,5)-RIGHT(D6,5)+1)"
   End With
   Application.Goto .Item(6)
End With
Erase Brr, Crr
End Sub
¥Î¦æ°Ê¸Ë¸mÂsÄý½×¾Â¾Ç²ß«Ü¤è«K,ÁÂÁ½׾¸gÀç¹Î¶¤
½Ð¤j®a¤@°_¤W½×¾Â¨Ó¥æ¬y

TOP

¦^´_ 2# Andy2483


    ¤Ó·PÁ«e½ú¤F~´ú¸Õ­×§ï¥Ø«e³£¥i¥H¹B¥Î¡A½Ð°Ý³o¬O«ç»ò¼gªº©O¡A¦pªG¦³¾l¸Îªº¸Ü§Æ±æ¥i¥H¥[¤W¨C¤@¦æµù¸Ñ¡AÅý§Ú°Ñ¦Ò¾Ç²ß ·PÁ·PÁÂ

TOP

¦³¸ß°Ý¨ì¥t¤@¦ì«e½ú¦¹¤èªkµ{¦¡§ó²«K¡A¥i±¤§Ç¸¹¤£·|¦Û°Ê¶]¥X¡A¸ê½è¾q¶w¤£ª¾¹D¸Ó¦p¦ó­×§ï
  1. Sub sdyt()
  2. For k = 3 To 5
  3.     For i = 1 To Range("p" & k).Value
  4.         Range("a" & i + 5 + r) = i
  5.         Range("c" & i + 5 + r) = Range("M" & k).Value
  6.         Range("D" & i + 5 + r) = Range("N" & k).Value + Range("a" & i + 5 + r) - 1
  7.     Next
  8.     r = r + i - 1
  9.   Next
  10. End Sub
½Æ»s¥N½X

TOP

¥»©«³Ì«á¥Ñ Andy2483 ©ó 2023-6-26 07:49 ½s¿è

¦^´_ 3# abc9gad2016


    ÁÂÁ«e½ú¦^´_,Åwªï«e½ú±`¤W½×¾Â¤@°_¾Ç²ß

¥H¤U¬O¤µ¤Ñ«á¾Ç½Æ²ßªº¤ß±oµù¸Ñ,½Ð«e½ú°Ñ¦Ò,½Ð¦U¦ì«e½ú«ü±Ð


Option Explicit
Sub TEST()
Dim Brr, Crr, V&, i&, R, N&, S%
'¡ô«Å§iÅܼÆ(&¬Oªø¾ã¼Æ,%¬Oµu¾ã¼Æ,¨S¦³±a²Å¸¹ªº¬O³q¥Î«¬ÅܼÆ)
Brr = Range([§Ç¸¹·s¼W!Q3], [§Ç¸¹·s¼W!M65536].End(xlUp))
'¡ô¥OBrrÅܼƬO ¤Gºû°}¦C,¥HM~QÄæÀx¦s®æ­È±a¤J°}¦C¤¤
ReDim Crr(1 To 60000, 1 To 11)
'¡ô¥OCrrÅܼƬO ¤GºûªÅ°}¦C,Áa¦V½d³ò1~6¸U¯Á¤Þ¸¹,¾î¦V½d³ò1~11¯Á¤Þ¸¹
For i = 1 To UBound(Brr)
'¡ô³]¶¶°j°é,i±q1¨ìBrr°}¦CÁa¦V³Ì¤j¯Á¤Þ¦C¸¹
   S = IIf(Brr(i, 2) <= Brr(i, 3), 1, -1)
   '¡ô¥OSÅܼƬO 1©Î -1
   For R = Val(Brr(i, 2)) To Val(Brr(i, 3)) Step S
   '¡ô³]¶¶°j°é,R±qBrr°}¦C­È(§Ç¸¹-«e¨ì §Ç¸¹-«á),°j°é¯Å¶Z¬O SÅܼÆ
      V = V + 1
      '¡ô¥OVÅܼƲ֥[1 (³o¬O­n°O¿ý²Ö­pªº°}¦C¯Á¤Þ¦C¸¹)
      N = N + 1
      '¡ô¥ONÅܼƲ֥[1 (³o¬O­n²Ö­p¶µ¦¸Ä檺¶µ¦¸)
      Crr(V, 1) = N
      '¡ô¥OCrr°}¦C(²Ö­pªº°}¦C¯Á¤Þ¦C¸¹,²Ä1Äæ)°}¦C­È¬O NÅܼÆ
      Crr(V, 3) = Brr(i, 1)
      '¡ô¥OCrr°}¦C(²Ö­pªº°}¦C¯Á¤Þ¦C¸¹,²Ä3Äæ)°}¦C­È¬O ,
      '¬Oi°j°é²Ä1ÄæBrr°}¦C­È(¾÷ºØ)

      Crr(V, 4) = R
      '¡ô¥OCrr°}¦C(²Ö­pªº°}¦C¯Á¤Þ¦C¸¹,²Ä4Äæ)°}¦C­È¬O R°j°é¼Æ
      Crr(V, 11) = Brr(i, 5)
      '¡ô¥OCrr°}¦C(²Ö­pªº°}¦C¯Á¤Þ¦C¸¹,²Ä11Äæ)°}¦C­È¬O (ª©¥»)
   Next
   N = 0
   '¡ô¥ONÅܼÆÂk¹s (¶µ¦¸Âk¹s)
Next
If V = 0 Then Exit Sub
'¡ô¥O¦pªG¨S¦³¸ê®Æ´Nµ²§ôµ{¦¡°õ¦æ
Sheets("§Ç¸¹·s¼W").UsedRange.Offset(5, 0).Delete
'¡ô¥O¸ê®Æ§R°£
With Sheets("§Ç¸¹·s¼W").[A6].Resize(V, 11)
'¡ô¥H¤U¬OÃö©ó±q[A6]Àx¦s®æ¶}©lÂX®i¥²­nÀx¦s®æ½d³òªºµ{§Ç
   .Value = Crr
   '¡ô¥OÀx¦s®æ­È¬O Crr°}¦C­È
   With .Columns(6)
   '¡ô¥H¤U¬O³o½d³òÀx¦s®æ²Ä6Ä檺µ{§Ç
      .Value = "=IF(E6="""","""",RIGHT(E6,5)-RIGHT(D6,5)+1)"
      '¡ô¥O³o²Ä6Äæ­È¬O ¤½¦¡~~   (PS:¥u­nµ¹²Ä1¦Cªº¤½¦¡,EXCEL·|¦Û°Ê¤U¨ê)
   End With
   Application.Goto .Item(6)
End With
Erase Brr, Crr
'¡ô¥OÄÀ©ñÅܼÆ
End Sub
¥Î¦æ°Ê¸Ë¸mÂsÄý½×¾Â¾Ç²ß«Ü¤è«K,ÁÂÁ½׾¸gÀç¹Î¶¤
½Ð¤j®a¤@°_¤W½×¾Â¨Ó¥æ¬y

TOP

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