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

[Âà¶K] For...Next »P For Each...Next °j°éªº°ò¥»·§©À

[Âà¶K] For...Next »P For Each...Next °j°éªº°ò¥»·§©À

¥»©«³Ì«á¥Ñ Hsieh ©ó 2010-5-10 17:42 ½s¿è

cjc
³X«È


   ½Ð°Ý¤£¦PÀɮתº¸ê®Æ½Æ»s
« ©ó: 2005-04-11, 10:22:45 »      

--------------------------------------------------------------------------------
¦U¦ì¦n,§Ú¦³¨â­ÓÀÉ®×:

ÀÉ®× A :
A    B     C     D     E
1 ª««~ ¤½¥q1 ¤½¥q2  ¤½¥q3  ¤½¥q4
2 001 5    10
3 002       7     12    22

ÀÉ®× B :
D      E...........K
1 ¤½¥q1 001   15
2 ¤½¥q2 001   10
2 ¤½¥q2 002   7
3 ¤½¥q3 002   12
4 ¤½¥q4 002   22

¥Ñ©óª««~ºØÃþ¦³¤W¦ÊºØ,¥i§_±N A Àɮתº¸ê®Æ(15,10,7,12,22....)¦Û°Ê¨ú¥N©Î¶ñ¤J B ÀɮשO?
ÁÂÁ  

« ³Ì«á½s¿è®É¶¡: 2005-04-11, 10:31:11 ¥Ñ ¤p»x »  ¦VªO¥DÀËÁ|    61.229.1.159 (?)  



cjc
³X«È


   Re: ½Ð°Ý¤£¦PÀɮתº¸ê®Æ½Æ»s
« ¦^ÂФ峹 #1 ©ó: 2005-04-11, 10:24:45 »      

--------------------------------------------------------------------------------
¯u©êºp,¤£ª¾¬°¦ó¤å³¹¶K¥X¨Ó·|³o¼Ë

¦^ÂÐ:
¦]¬°§A¥[¤Ó¦hªÅ¥Õ¤F >:
¤£ª¾¦p¦ó¥[¤Jªí®æ¥N½X¨Ó±Æª©ªº¸Ü,½Ð¥ý¨ì·s¤â¸ÕÅç°Ï¸ÕÅç¤@¤UOK
¤£µM§A¤]¥ý¹wÄý¤@¤U


« ³Ì«á½s¿è®É¶¡: 2005-04-11, 10:34:29 ¥Ñ ¤p»x »  ¦VªO¥DÀËÁ|    61.229.1.159 (?)  



cjc
³X«È


   Re: ½Ð°Ý¤£¦PÀɮתº¸ê®Æ½Æ»s
« ¦^ÂФ峹 #2 ©ó: 2005-04-11, 11:34:40 »      

--------------------------------------------------------------------------------
¯u©êºp,§Ú§â¥¦°µ¦¨ªí®æ,À³¸Ó¤ñ¸û²M·¡¤F
A B C D E
1 ª««~ ¤½¥q1 ¤½¥q2 ¤½¥q3 ¤½¥q4
2 001 15 10   
3 002  7 12 22


C D ... K
1 ¤½¥q1 001  15
2 ¤½¥q2 001  10
3 ¤½¥q2 002  7
4 ¤½¥q3 002  12
5 ¤½¥q4 002  22


¦VªO¥DÀËÁ|    61.229.1.159 (?)  



leonchou
½×¾ÂºûÅ@¸s

Â÷½u

¤å³¹: 1214


     Re: ½Ð°Ý¤£¦PÀɮתº¸ê®Æ½Æ»s
« ¦^ÂФ峹 #3 ©ó: 2005-04-11, 23:25:54 »      

--------------------------------------------------------------------------------
1. ¥H¤U½d¨Ò¡A¨â­ÓÀɮ׻ݤw¶}±Ò
2. ÀɮצWºÙ¨Ì¹ê»Ú±¡§Î­×§ï

Sub zz()
Set a = Workbooks("ÀÉ®×A.xls").Sheets(1)
Set b = Workbooks("ÀÉ®×B.xls").Sheets(1)
lastrow = a.[A1].End(xlDown).Row
lastcol = a.[A1].End(xlToRight).Column
rb = 1
For c = 2 To lastcol
¡@¡@For r = 2 To lastrow
¡@¡@¡@¡@If a.Cells(r, c) <> "" Then
¡@¡@¡@¡@¡@¡@b.Cells(rb, 3) = a.Cells(1, c)
¡@¡@¡@¡@¡@¡@b.Cells(rb, 4) = a.Cells(r, 1)
¡@¡@¡@¡@¡@¡@b.Cells(rb, 11) = a.Cells(r, c)
¡@¡@¡@¡@¡@¡@rb = rb + 1
¡@¡@¡@¡@End If
¡@¡@Next r
Next c
End Sub


¦VªO¥DÀËÁ|    203.79.168.37 (?)  

--------------------------------------------------------------------------------
BEFORE ASKING, YOU SHOULD RTFH, RTFM, STFW...



oobird
¥Yºlªº¤ì¤u
½×¾ÂºûÅ@¸s

Â÷½u

¤å³¹: 5270



     Re: ½Ð°Ý¤£¦PÀɮתº¸ê®Æ½Æ»s
&laquo; ¦^ÂФ峹 #4 ©ó: 2005-04-12, 08:21:38 &raquo;      

--------------------------------------------------------------------------------
lenchou¥S¡G«Ü¦nªºÅܶq½d¨Ò¡C¤p§Ì¤£À´«á­±ªºrb = rb + 1¡A¤ÎNext r¡BNext c»P ¥u¦³¼g"Next "ªº®t§O¡A¯à±Ò»X¤@¤U¶Ü¡HÁÂÁ¡C



¦VªO¥DÀËÁ|    61.217.102.234 (?)  

--------------------------------------------------------------------------------
µ²Ãf«Ý¼z§g


cjc
³X«È


   Re: ½Ð°Ý¤£¦PÀɮתº¸ê®Æ½Æ»s
&laquo; ¦^ÂФ峹 #5 ©ó: 2005-04-12, 10:52:21 &raquo;      

--------------------------------------------------------------------------------
·PÁÂ lenchou¥S¦^ÂÐ
¤£¹L¥Ñ©óÀÉ®×Bªº C ,D ¦C¸ê®Æ¤w¸g¦s¦b,¥u»Ý±N K ¦CªºªÅ¥Õ¸ê®Æ¶ñ¤J,¶·­n«ç»ò­×§ï©O?
ÁÂÁÂ!

¦VªO¥DÀËÁ|    61.229.1.159 (?)  



yem
³X«È


   Re: ½Ð°Ý¤£¦PÀɮתº¸ê®Æ½Æ»s
&laquo; ¦^ÂФ峹 #6 ©ó: 2005-04-12, 11:49:55 &raquo;      

--------------------------------------------------------------------------------
¤Þ¥Î¦Û: cjc ©ó 2005-04-12, 10:52:21
·PÁÂ lenchou¥S¦^ÂÐ
¤£¹L¥Ñ©óÀÉ®×Bªº C ,D ¦C¤w¸g¦s¦b,¥u»Ý±N K ¦CªºªÅ¥Õ¸ê®Æ¶ñ¤J,¶·­n«ç»ò­×§ï©O?
ÁÂÁÂ!


C,D¸ê®Æ¤w¦s¦b¡A
³o»ò¦n°Ú~~
¨º¥Î¤½¦¡§ó¤è«K¤F

K1¤½¦¡
=INDIRECT("[Book1]Sheet1!R"&MATCH(D1,[Book1]Sheet1!$A$1:$A$11,0)&"C" &MATCH(C1,[Book1]Sheet1!$A$1:$E$1,0),0)



¤½¦¡¤¤¡G
BooK1´«¦¨ÀÉ®×Aªº¦W¦r¡A
$A$1:$A$11¡A¤Î$A$1:$E$1´N­nµø¯u¥¿ªº¸ê®Æ§ïÅܽd³òªø«×¤F

¦VªO¥DÀËÁ|    218.175.222.56 (?)  



cjc
³X«È


   Re: ½Ð°Ý¤£¦PÀɮתº¸ê®Æ½Æ»s
&laquo; ¦^ÂФ峹 #7 ©ó: 2005-04-12, 12:52:36 &raquo;      

--------------------------------------------------------------------------------
·PÁÂ yem ¥S¦^ÂÐ
§Ú±N¤½¦¡®M¤Jk1-k5,©Ò±o¨ìªºµª®×³£¬O¤@¼Ë
¦pªG¦³¤W¤dµ§ªº¸ê®Æ,¥i¥H±N¤½¦¡¤@¦¸®M¤J¶Ü?

¦VªO¥DÀËÁ|    61.229.1.159 (?)  



yem
³X«È


   Re: ½Ð°Ý¤£¦PÀɮתº¸ê®Æ½Æ»s
&laquo; ¦^ÂФ峹 #8 ©ó: 2005-04-12, 13:38:48 &raquo;      

--------------------------------------------------------------------------------
¤Þ¥Î¦Û: cjc ©ó 2005-04-12, 12:52:36
·PÁÂ yem ¥S¦^ÂÐ
§Ú±N¤½¦¡®M¤Jk1-k5,©Ò±o¨ìªºµª®×³£¬O¤@¼Ë
¦pªG¦³¤W¤dµ§ªº¸ê®Æ,¥i¥H±N¤½¦¡¤@¦¸®M¤J¶Ü?


³o¬Ok1ªº¤½¦¡¡Ak2~k5­n±qk1©¹¤U©Ô®@!!  

¦VªO¥DÀËÁ|    218.175.222.56 (?)  



leonchou
½×¾ÂºûÅ@¸s

Â÷½u

¤å³¹: 1214


     Re: ½Ð°Ý¤£¦PÀɮתº¸ê®Æ½Æ»s
&laquo; ¦^ÂФ峹 #9 ©ó: 2005-04-12, 23:41:45 &raquo;      

--------------------------------------------------------------------------------
¤Þ¥Î¦Û: oobird ©ó 2005-04-12, 08:21:38
lenchou¥S¡G«Ü¦nªºÅܶq½d¨Ò¡C¤p§Ì¤£À´«á­±ªºrb = rb + 1¡A¤ÎNext r¡BNext c»P ¥u¦³¼g"Next "ªº®t§O¡A¯à±Ò»X¤@¤U¶Ü¡HÁÂÁ¡C


´N¬O·Ó¨î¦¡ªº¥Îªk¦Ó¤w...

¸`¿ý¦ÛVBA»²§U»¡©ú --

¤@. For...Next ³¯­z¦¡

¥H¯S©w¦¸¼Æ¨Ó­«½Æ°õ¦æ¤@¬q³¯­z¦¡¡C

»yªk
For counter = start To end [Step step]
[¨ä¥L³¯­z¦¡]
[Exit For]
[¨ä¥L³¯­z¦¡]

Next [counter]

ªþµù ¦pªG±z¬Ù²¤ Next ³¯­z¦¡¤¤ªº­p¼Æ¾¹¡A¤´¥i¥H°õ¦æ°j°é¡A¦ý¦pªG Next ³¯­z¦¡¤ñ¥¦¬Û¹ïÀ³ªº For ³¯­z¦¡¥ý°õ¦æ¡A«h·|²£¥Í¿ù»~¡C

¤G. For Each...Next ³¯­z¦¡

°w¹ï¤@­Ó°}¦C©Î¶°¦X¤¤ªº©Ò¦³¤¸¯À¡A­«½Æ°õ¦æ¤@¬q³¯­z¦¡¡C

»yªk
For Each element In collection
[¨ä¥L³¯­z¦¡]
[Exit For]
[¨ä¥L³¯­z¦¡]

Next [element]

ªþµù ¦pªG±z¬Ù²¤ Next ³¯­z¦¡¤¤ªº¤¸¯À¡A¤´¥i¥H°õ¦æ°j°é¡A¦ý¦pªG Next ³¯­z¦¡¤ñ¥¦¬Û¹ïÀ³ªº For ³¯­z¦¡¥ý°õ¦æ¡A«h·|²£¥Í¿ù»~¡C

--------------------------------------------------------------------------------

§Ú­ËÁÙ¨S¹J¹L "Next ³¯­z¦¡¤ñ¥¦¬Û¹ïÀ³ªº For ³¯­z¦¡¥ý°õ¦æ" ¦Óµo¥Í¿ù»~ªº±¡§Î¡A
©Ò¥H§Ú¤@¦V¥u¦b For...Next «á­±¥[ counter ¡A¥H©M For Each...Next ³¯­z¦¡¦³©Ò°Ï§O¦Ó¤w¡A¦p¦PHelp©Ò»¡¡G°£«D¹J¨ì¿ù»~¡A§_«h¥[»P¤£¥[³£¨S®t¡C
¦pªG­n»¡¥[¦³¤°»ò¦n³B¡A¤j·§´N¬O¤£©ö¥X¿ù¡A¦Ó¥B¦p¦¹¨Ò¤¤¨Ï¥Î¦h­Ó For ... Next ªº±_ª¬°j°é®É¡A¸û®e©ö¤À¿ë­þ­Ó¬O­þ­Ó¡C
¨Ïµ{¦¡½X¸û©ö©ó¾\Ū¡A¬O­Ó¦n²ßºD¡C

§â»²§U»¡©ú¦³ªºªF¦è®³¨Óµo±Ð¾Ç¤å³¹¡A¦pªG¨S¦³­È±o¤@®Ñªº¤ß±o¡A¨S¤°»ò·N«ä¹ï§a?

§Ñ¤F»¡ rb = rb + 1 ªº·N«ä...
rb ¬O°µ¬° BÀɮצC¸¹ªºÅܼơA¤@¦C¤@¦C±µµÛ©¹¤U¶ñ¤J¸ê®Æ¡C
AÀɮפw¦³ For ... Next ªº­p¼ÆÅܶq°µ¬°Äæ¦C¸¹¡A
BÀɮתºÄ渹¬O©T©w¡A¦Ó¦C¸¹»P AÀɤ£¦P¡A©Ò¥H¥t³]ÅܼơC

&laquo; ³Ì«á½s¿è®É¶¡: 2005-04-12, 23:46:32 ¥Ñ leonchou &raquo;  ¦VªO¥DÀËÁ|    203.79.168.37 (?)

¦^´_ 12# handsometrowa

h¤jªºªí¹F¯à¤O¯uªº«D±`±j¡A¤@¬Ý´NÅý¤H¯à»â®©¡A«D±`·PÁ¡C

TOP

¦^´_ 11# yagami12th


For  Each ªº°j°é  §A§â¥L¤½¦¡³o¼Ë¤l°O

FOR  EACH   OO  IN    XX  ½Ðµw­I

OO (OO¬O¬YÁ`«¬ºA  ¨Ò¦pRange   String µ¥.....)   
IN   
XX  ( XX ¬OOOªº¶°¦XÁ`¥Nªí)

°²³]§A¥Î  For each  range  in  "ªí³æ"    ³o­ÓRange ¥Nªí Àx¦s®æ     "ªí³æ" ´N¬O¸Ì­±¦³«Ü¦hÀx¦s®æªº¶°¦X

°²³]¤@­Óªí³æ¸Ì­±¦³3X3 =9­ÓÀx¦s®æ §A©w¸q´N¥s°µ"ªí³æ"   ¨º³o­Ó°j°é  ¨Ì¾Ú   ¨C­ÓRange  ­n¦b   3X3 ªº"ªí³æ"½d³ò¤º    ¨C¦¸³£°õ¦æ¤@¦¸³¯­z¦¡

³o­Ó°j°é´N·|°õ¦æ¤E¹M      ©Ò¥H  ­n¥ý©ú½T©w¸q §A­n°õ¦æªº°j°é  ²Ä¤@­Ó Ãþ«¬¬O¤°»ò  µM«á³o­ÓÃþ«¬¦³¦h¤Ö¼Æ¶qªº¶°¦X

¦AÅý¥L¥h¶]¡A³o¼Ë¤l¸ÑÄÀÀ³¸Ó¤ñ¸û²M·¡¤F§a¡C

TOP

for eatch §Ú¬Ý®ÑÁÙ¬O¨S¿ëªk»â®©¡A¥Ø«e¥u·|ºâ³æªºfor next¡C

TOP

ÁÂÁª©¥D,¨ü±Ð¤F,¤S¥i¥H©¹¤U¬ã¨s,³o¤å³¹¦³¦n¤j¥bÁÙ¨S§ËÀ´

TOP

¦^´_ 8# aa7551


    d(.[B1] &"-"& .[A1]) ="TOTAL CNT"
¾Ç®üµL²P_¤£®¢¤U°Ý

TOP

ª©¥D:¤@.¨Ì§Aªºµ{¦¡½X...d(a & a.Offset(, 1)) = d(a & a.Offset(, 1)) + a.Offset(, 2)
³o¤@¬q ¦n¹³·|¥X²{¬O"01J0507001",¦Ó¤£¬O"J0507001-01",§Ú¸ÕµÛ§â¥¦§ï¦¨d(a.Offset(, 1)&"-"+a) = d(a.Offset(, 1)&"-"&a) + a.Offset(, 2)¤G.­n½Ð±Ð§Aªº¬O:d(.[A1] & .[B1]) = .[C1] §e²{ªº¬O"PL NOREF",¦pªG§Ú§â¥¦§ï¦¨ d(.[B1] &"-"& .[A1]) = .[C1],¨º§e²{´N·|¬O"REF-PL NO",¨º±µ¤U¨Ó§Ú·Q§âSHEET2¤WªºBÄæ¦W¤]§ó§ï¬°"TOTAL CNT",¨º­n¦p¦ó­×§ï

TOP

¦^´_ 6# et5323
ÁÂÁÂet5323«e½ú´£¨Ñ¦p¦¹ºëÅPªº¤å³¹
¥»¯¸Ác¤¤ª©¥»ªº·|­û¤]¤£¦b¤Ö¼Æ,½¦¨Ác¤¤¦rÅéÅý¤j®a®e©ö¾\Ū

    ¦b¤@¼Óªº°ò¦¤W²K¥u¨¬«¢,´N¬O¥i¯à¦n¦h³N»y¤£¤@¼Ë¡A§Ú¥u§â¡§°j°é¡¨§ï¦¨¤F¡§¦^°é¡¨¡G

µ²ºc¤Æªºµ{¦¡³]­p¥]§t¤TºØ°ò¥»µ²ºc¡G¶¶§Çµ²ºc¡B¿ï¾Üµ²ºc©M¦^°éµ²ºc¡C
¦^°éµ²ºc¬O«ü¦b°õ¦æµ{¦¡®É¡A®Ú¾Ú±ø¥óªº¯u°²¡A¨Ó§PÂ_¬O§_­«½Æ°õ¦æ¨ä¤¤¬Y¬q¥N½X¡C­nº¡¨¬¬Y­Ó±ø¥ó¡A´N¤@ª½­«½Æ°õ¦æ³o¬q¥N½X¡Aª½¨ì¤£º¡¨¬±ø¥ó¬°¤î¡C¥]¬A¡GFor¡K¡KNext¡BFor Each¡K¡KNext¡BDo¡K¡Kloop¡Bwhile¡K¡K Wend¥|ºØ¦^°é»y¥y¡C
1. For¡KNext»y¥y
For¡KNext¦^°éÄÝ©ó­p¼Æ«¬¦^°é¡Aµ{¦¡«ö·Ó¸Óµ²ºc¤¤«ü©wªº¦^°é¦¸¼Æ¨Ó°õ¦æ¦^°éÅ鳡¤À¡C

For¡K¡KNext»y¥yªº®æ¦¡¦p¤U¡G
    For¦^°éÅܼÆ=ªì©l­È TO²×­È [Step¨Bªø]
       [¦^°éÅé]
    Next [¦^°éÅܼÆ]
¦pªG¬Ù²¤ Next»y¥y¤¤ªº[¦^°éÅܼÆ]¡A´N¹³[¦^°éÅܼÆ]¦s¦b®É¤@¼Ë°õ¦æ¡C
    ¦b¦¹®æ¦¡¤¤¡A¨Ï¥Î¤F³o¼Ë´X­Ó·§©À¡G
    (1)¦^°éÅܼơG¥Î©ó²Î­p¦^°é¦¸¼ÆªºÅܼơA¦^°éªº¹Lµ{´N¬O¸ÓÅܼƬO±q¬Y­Ó­ÈÅܤƨì¥t¤@­Ó­Èªº¹Lµ{¡C
    (2)ªì©l­È¡G¥Î©ó³]¸m¦^°éÅܼƪºªì©l¨ú­È¡C
    (3)²×­È¡G¥Î©ó³]¸m¦^°éÅܼƪº³Ì«á¨ú­È¡C
    (4)¨Bªø¡G¥Î©ó¨M©w¦^°éÅܼƨC¦¸¦^°é®ÉÅܤƪº¼Æ­È¡A§Y¦^°éÅܼƦbÅܤƮɪº¼W­È¡C¦pªG¬Ù¨Bªøªº¸Ü¡A¨ä¹w³]­È¬°1¡C¨Bªøªº¨ú­È¥i¥H¬°¥¿¡A¤]¥i¥H¬°­t¡C­Yªì©l­È¤p©ó²×­È¡A«h¥²±N¨Bªø³]¬°¥¿­È¤~¦³¥i¯à°õ¦æ¦^°éÅé¡F­Yªì©l­È¤j©ó²×­È¡A«h¥²¶·±N¨Bªø³]¬°­t­È¤~¦³¥i¯à¦æ¦^°éÅé¡C
    (5)¦^°éÅé¡G»Ý­n­«½Æ°õ¦æªº¥N½X³¡¤À¡A¥i¥H¬O¤@­Ó©Î¦h­Ó»y¥y¡C
    (6)Next[¦^°éÅܼÆ]¡G¥Î©óµ²§ô¤@¦¸For¦^°é¡A®Ú¾Ú²×­È©M²{¦b¦^°éÅܼƪº­Èªº¤j¤pÃö«Y¨M©w¬O§_°õ¦æ¤U¤@¦¸¦^°é¡C¨ä¤¤ªº¦^°éÅܼƪº¦WºÙ¥²¶·»P¦^°é¶}©l®Éªº¦^°éÅܼƦWºÙ¬Û¦P¡C

For¡KNext»y¥y¦^°éªº°õ¦æ¹Lµ{(¤u§@­ì²z)¡G
¥ý±N¦^°éÅܼƨú¬°ªì©l­È¡AµM«áÀËÅç¦^°éÅܼƪº¨ú­È¬O§_¶W¥X²×­È¡A­Y¦^°éÅܼƨS¦³¶W¥X²×­È¡A«h°õ¦æ¤@¦¸¦^°éÅé»y¥y¡AµM«á±N¦^°éÅܼƥ[¤W¨Bªø½á­Èµ¹¦^°éÅܼƥ»¨­¡A¦A»P²×­È¶i¦æ¤ñ¸û¡Aª½¨ì¦^°éÅܼƶW¥X²×­È®É¡A°h¥X¦^°é¡A°õ¦æ«á­±ªº»y¥y¡C©Ò¿×¶W¥X²×­È¬O«ü¡G­Y¨Bªø¬°¥¿­È¡A«hÀËÅç¦^°éÅܼƬO§_¤j©ó²×­È¡F­Y¨Bªø¬°­t­È¡A«hÀËÅç¦^°éÅܼƪº¨ú­È¬O§_¤p©ó²×­È¡C
For¡KNext»y¥yµ²§ô«á·|ªð¦^[¦^°éÅܼÆ]ªº­È¡A¦ý¥¦¤@©w¤£µ¥©ó[²×­È]:
Sub t()
Dim i
For i=1 to 10
Next
End  sub
³Ì«ái¬O¦h¤Ö©O¡H¤£ºÞ¬O¦h¤Ö¡A¥¦¤@©w¤£¬O10¡G
Sub t1()
    Dim i, j
    For i = 1 To 10
        j = j + 1
        MsgBox "¨Bªø­È¬°1,²Ä" & j & "¦¸¦^°é[¦^°éÅܼÆ]ªº­È:" & i
    Next
    MsgBox "¦^°é¦¸¼Æ:" & j & Chr(13) & "³Ì«á[¦^°éÅܼÆ]ªº­È:" & i
End Sub

Sub t2()
    Dim i, j
    For i = 1 To 10 Step 1.6
        j = j + 1
        MsgBox "¨Bªø­È¬°1.5,²Ä" & j & "¦¸¦^°é[¦^°éÅܼÆ]ªº­È:" & i
    Next
    MsgBox "¦^°é¦¸¼Æ:" & j & Chr(13) & "³Ì«á[¦^°éÅܼÆ]ªº­È:" & i
End Sub
¦b¦^°éÅ餤¤]¥i¥H§ïÅÜ[¦^°éÅܼÆ]ªº­È¡A¦ý³o·|¨Ïµ{¦¡½Xªº¾\Ū©M½Õ¸ÕÅܱo«D±`§xÃø¡A¤@¯ë¤£´£­Ò³o¼Ë°µ:
Sub t3()
    Dim i, j
    For i = 1 To 10
        i = i + 1
        j = j + 1
        MsgBox "¨Bªø­È¬°1.5,²Ä" & j & "¦¸¦^°é[¦^°éÅܼÆ]ªº­È:" & i
    Next
    MsgBox "¦^°é¦¸¼Æ:" & j & Chr(13) & "³Ì«á[¦^°éÅܼÆ]ªº­È:" & i
End Sub

¦bFor¡KNext¦^°é¤¤¡A¥u­n¨Bªø¤£¬°0¡A´N¥Ã»·¤£·|¥X²{¦º¦^°é¡C¦]¬°¥u­n¨Bªø¤£¬°0¡AµL½×©l­È©M²×­È¤§¶¡¬Û®t¦h»ò¤j¡AÁ`¥i¥H¸g¹L¦³­­¦¸ªº¦^°é¡A¨Ï©l­È¶W¥X²×­È¡A±q¦Ó¸õ¥X¦^°é¡C¥Ñ¦¹¥i¨£¡AFor¡KNext¾A¥Î©ó¹w¥ýª¾¹D¦^°é¦¸¼Æªº±¡ªp¡C
¦b¬Y¨Ç±¡ªp¤U¡A¥i¯à»Ý­n¦b¦^°éÅܼƨS¦³¶W¥X²×­È¤§«e´N¸õ¥X¦^°é¡A³o®É¥i¥H¥ÎExit For»y¥y¡A·íº¡¨¬¬YºØ¯S®íªº±ø¥ó®É¡A´N´£«e¸õ¥X¦^°é¡C

±qFor¡KNext»y¥yªº®æ¦¡¤¤¥i¥H¬Ý¨ì¡G¨ä¤¤ªº¦^°éÅé¬O¥i¿ïªº¡C­Y¬Ù²¤¤F¦^°éÅé¡A§YFor¦^°éªº¦^°éÅ餺¨S¦³¥ô¦ó¨ãÅ骺»y¥y¡A«h¨ä¥u¬O°_¨ì©µ®Éªº§@¥Î¡C¦]¬°·í¦^°é¤F¤@©w¦¸¼Æ«áÁö¤£°õ¦æ¥ô¦ó¾Þ§@¡A¦ý«oªá¶O¤F¤@©w®É¶¡¡A¬G¥i§@¬°©µ®É¤u¨ã¨Ï¥Î¡C¦ý­nª`·Nªº¬O¥Ñ©ó²{¦b¹q¸£ªº³t«×³£¤ñ¸û§Ö¤F¡A¦pªG¦^°é¦¸¼Æ¤ñ¸û¤Öªº¸Ü±N¤£·|¹F¨ì¹w´Áªº®ÄªG¡A¦]¦¹­n¾A·í¿ï¾Ü¦^°é¦¸¼Æ¡C

2.For Each¡KNext»y¥y
FOR¡K¡KNext»y¥y»PFor¡KNext»y¥y¦³¨ÇÃþ¦ü¡A¦ý¥¦­Ì¦³«Ü¤jªº°Ï§O¡G«eªÌ¬O¥Ñ«ü©w©Î¶°¦X¤¤ªº¤¸¯À¨Ó±±¨î¦^°é¡A¦Ó«áªÌ¬O¥Ñ¦^°éÅܼƨӱ±¨î¦^°é¹Lµ{¡C¥Ñ¦¹¥i¨£¡AFor Each¡K»y¥y¬O¤£»Ý­n¹w¥ýª¾¹D¦^°é¦¸¼Æªº¡A«ü©w°}¦C©Î¶°¦X¤¤ªº¤¸¯À­Ó¼Æ´N¬O¦^°é¦¸¼Æ¡C¸Ó»y¥yªº¨Ï¥Î®æ¦¡¬°¡G
    For Each¦^°éÅܼÆIn°}¦C©Î¶°¦X
        ¦^°éÅé
    Next¦^°éÅܼÆ
    ³oùتº¦^°éÅܼƥ²¶·¬OÅÜÅ髬(Variant)©Îª«¥ó«¬(Object)ªº¡C¹ï©ó°}¦C¡A¦^°éÅܼƥ²¶·¬OÅÜÅ髬ªº¡F¹ï©ó¶°¦X¡A¦pªG¶°¦X¤¤¥]§tª«¥ó¡A«h¦^°éÅܼÆÀ³¸Ó¬Oª«¥ó«¬¡A·íµM¤]¥i¥H¬OÅÜÅ髬¡C
·í¬Y¤@°}¦C©Î¶°¦Xùتº©Ò¦³¤¸¯À¶i¦æ¦P¤@¾Þ§@®É¡A´N»Ý­n¨Ï¥Î¸Ó»y¥y¤F¡C
¦P¼Ëªº¥i¥H¥ÎExit For»y¥y¡A·íº¡¨¬¬YºØ¯S®íªº±ø¥ó®É¡A´N´£«e¸õ¥X¦^°é¡C

For Each¡KNext»y¥yµ²§ô«á¡A¤£·|ªð¦^[¦^°éÅܼÆ]¡A³o»PFor¡KNext»y¥y¤£¤@¼Ë:
Sub t4()
    Dim c
    For Each c In Array(1, 2, "aa")
    Next
    MsgBox TypeName(c)
End Sub
Sub t5()
    Dim r As Range
    For Each r In [a1:a4]
    Next
    MsgBox TypeName(r)
End Sub

3.Do¡KLoop»y¥y
    Do¡KLoop¦^°é¬O®Ú¾Ú¬Y­Ó±ø¥ó¬O§_¦¨¥ß¨Ó¨M©w¬O§_¦^°é¡C¥¦¨Ã¤£­­¨î¦^°éªº¦¸¼Æ¡A¥u­nº¡¨¬±ø¥ó´NÄ~Äò¦^°é¡Aª½¨ì¤£º¡¨¬±ø¥ó®É¸õ¥X¦^°é¡Cª`·N­n¦b¦^°é¤¤§ïÅܱø¥ó¡A§_«hªº¸Ü¥i¯à·|³´¤J¦º¦^°é¡C

    Do¡KLoop»y¥y¦³¥|ºØ§Î¦¡¡G
§Î¦¡1¡G
DO
¦^°éÅé
Loop While ±ø¥ó
³oºØ§Î¦¡ªº°õ¦æ¹Lµ{¬O¡G¥ý°õ¦æ¤@¹M¦^°éÅé¡AµM«á¦A§PÂ_±ø¥ó¬O§_¦¨¥ß¡A­Y±ø¥ó¦¨¥ß¡A Ä~Äò¤U¤@¦¸¦^°é¡F§_«h¡A´N°h¥X¦^°é¡C

§Î¦¡2¡G
Do While ±ø¥ó
¦^°éÅé
Loop
³oºØ§Î¦¡¬O§â¡§While±ø¥ó¡¨©ñ¦b¦^°éÅ骺«e­±¡A¤]´N¬O»¡¥¦ªº°õ¦æ¹Lµ{¬O¥ý§PÂ_±ø¥ó¬O¥ß¡A¦A¨M©w¬O§_Ä~Äò¦^°é¡C

§Î¦¡3¡G
DO
¦^°éÅé
Loop Until ±ø¥ó
³oºØ§Î¦¡©M²Ä¤@ºØ§Î¦¡¦³¨ÇÃþ¦ü¡A¤]¬O¥ý°õ¦æ¦^°éÅé¡AµM«á¦A§PÂ_±ø¥ó¡C»P²Ä¤@ºØ§Î¦¡¤£¦P¡A³oºØ§Î¦¡¥u¦³·í±ø¥ó¤£¦¨¥ß¤~·|Ä~Äò¦^°é¡A§_«h´N°h¥X¦^°é¡C

§Î¦¡4¡G
DO Until ±ø¥ó
¦^°éÅé
Loop
³oºØ§Î¦¡©M²Ä¤GºØ§Î¦¡¦³¨ÇÃþ¦ü¡A¥ý§PÂ_±ø¥ó¡A¦A¨M©w¬O§_Ä~Äò¦^°é¡C»P¤§¤£¦Pªº¬O¡A³oºØ§Î¦¡¤]¬O·í±ø¥ó¤£¦¨¥ß¤~·|Ä~Äò¦^°é¡C

¥Ñ¤W­±¥|ºØ§Î¦¡ªº®æ¦¡¥i¥H¬Ý¥X¡G
    ²Ä¤@ºØ©M²Ä¤TºØ§Î¦¡¬O¥ý°õ¦æ¦^°éÅé¡AµM«á¦A§PÂ_±ø¥ó¡A±ø¥ó¦¨¥ß»P§_¡A¦Ü¤Ö°õ¦æ¤@¦¸¦^°éÅé¡F²Ä¤GºØ©M²Ä¥|ºØ§Î¦¡¡A«h¬O¥ý§PÂ_±ø¥ó¡A¦pªG±ø¥ó·í¡A¦^°éÅé¥i¯à¤@¦¸¤]¨S¦³°õ¦æ¡C¥B¡§While¡¨©M¡§Until¡¨¥¿¦n¬Û¤Ï¡A«eªÌ¬O±ø¥ó¦¨¥ß®É¤J¦^°é¡A¦Ó«áªÌ«h¬O±ø¥ó¤£¦¨¥ß®É¤~¶i¤J¦^°é¡C¨Ï¥Î®É¥i®Ú¾Ú»Ý­n¿ï¾Ü³Ì¾A·íªº§Î¦¡¡C

    ¦b«e­±For¡KNext»y¥y¤¤¤¶²ÐªºExit»y¥y¤]¾A¥Î©óDO¡KLoop»y¥y¡A¥u¬O§â¡§Exit For¡¨§ï¦¨¡§Exit Do¡¨§Y¥i¡A¥¦­Ìªº§@¥Î¬O¤@¼Ëªº¡A³£¬O¥Î¨Ó´£«e¸õ¥X¦^°éªº¡C

¸ê®Æ¨Ó·½:·L³n説©ú
¾Ç®üµL²P_¤£®¢¤U°Ý

TOP

¦b¤@楼ªº°ò础¤W²K¥u¨¬«¢,´N¬O¥i¯à¦n¦h术语¤£¤@样¡A§Ú¥u§â¡§´`环¡¨§ï¦¨¤F¡§¦^°é¡¨¡G

结Ìۤƪºµ{§Ç设计¥]§t¤TÏú°ò¥»结ÌÛ¡G顺§Ç结ÌÛ¡B选择结ÌÛ©M¦^°é结ÌÛ¡C
¦^°é结ÌÛ¬O«ü¦b执¦æµ{§Ç时¡A®ÚÕu条¥óªº¯u°²¡A来§P断¬O§_­«Î`执¦æ¨ä¤¤¬Y¬q¥N码¡C­n满¨¬¬Y个条¥ó¡A´N¤@ª½­«Î`执¦æ这¬q¥N码¡Aª½¨ì¤£满¨¬条¥ó为¤î¡C¥]¬A¡GFor¡K¡KNext¡BFor Each¡K¡KNext¡BDo¡K¡Kloop¡Bwhile¡K¡K Wend¥|Ïú¦^°é语¥y¡C
1. For¡KNext语¥y
For¡KNext¦^°é属¤_计数«¬¦^°é¡Aµ{§Ç«ö·Ó该结ÌÛ¤¤«ü©wªº¦^°é¦¸数来执¦æ¦^°éÊ^³¡¤À¡C

For¡K¡KNext语¥yªº®æ¦¡¦p¤U¡G
    For¦^°é变¶q=ªì©l­È TO终­È [Step¨B长]
       [¦^°éÊ^]
    Next [¦^°é变¶q]
¦pªG¬Ù²¤ Next语¥y¤¤ªº[¦^°é变¶q]¡A´N¹³[¦^°é变¶q]¦s¦b时¤@样执¦æ¡C
    ¦b¦¹®æ¦¡¤¤¡A¨Ï¥Î¤F这样¤L个·§©À¡G
    (1)¦^°é变¶q¡G¥Î¤_统计¦^°é¦¸数ªº变¶q¡A¦^°éªº过µ{´N¬O该变¶q¬O从¬Y个­È变¤Æ¨ì¥t¤@个­Èªº过µ{¡C
    (2)ªì©l­È¡G¥Î¤_设¸m¦^°é变¶qªºªì©l¨ú­È¡C
    (3)终­È¡G¥Î¤_设¸m¦^°é变¶qªº³Ì¦Z¨ú­È¡C
    (4)¨B长¡G¥Î¤_决©w¦^°é变¶q¨C¦¸¦^°é时变¤Æªº数­È¡A§Y¦^°é变¶q¦b变¤Æ时ªº¼W­È¡C¦pªG¬Ù¨B长ªº话¡A¨äÀq认­È为1¡C¨B长ªº¨ú­È¥i¥H为¥¿¡A¤]¥i¥H为负¡C­Yªì©l­È¤p¤_终­È¡A则¥²将¨B长设为¥¿­È¤~¦³¥i¯à执¦æ¦^°éÊ^¡F­Yªì©l­È¤j¤_终­È¡A则¥²须将¨B长设为负­È¤~¦³¥i¯à¦æ¦^°éÊ^¡C
    (5)¦^°éÊ^¡G»Ý­n­«Î`执¦æªº¥N码³¡¤À¡A¥i¥H¬O¤@个©Î¦h个语¥y¡C
    (6)Next[¦^°é变¶q]¡G¥Î¤_结§ô¤@¦¸For¦^°é¡A®ÚÕu终­È©M现¦b¦^°é变¶qªº­Èªº¤j¤p关¨t决©w¬O§_执¦æ¤U¤@¦¸¦^°é¡C¨ä¤¤ªº¦^°é变¶qªº¦W称¥²须ÉO¦^°é开©l时ªº¦^°é变¶q¦W称¬Û¦P¡C

For¡KNext语¥y¦^°éªº执¦æ过µ{(¤u§@­ì²z)¡G
¥ý将¦^°é变¶q¨ú为ªì©l­È¡AµM¦Z检验¦^°é变¶qªº¨ú­È¬O§_¶W¥X终­È¡A­Y¦^°é变¶q没¦³¶W¥X终­È¡A则执¦æ¤@¦¸¦^°éÊ^语¥y¡AµM¦Z将¦^°é变¶q¥[¤W¨B长赋­È给¦^°é变¶q¥»¨­¡A¦AÉO终­È进¦æ¤ñ较¡Aª½¨ì¦^°é变¶q¶W¥X终­È时¡A°h¥X¦^°é¡A执¦æ¦Z­±ªº语¥y¡C©Ò谓¶W¥X终­È¬O«ü¡G­Y¨B长为¥¿­È¡A则检验¦^°é变¶q¬O§_¤j¤_终­È¡F­Y¨B长为负­È¡A则检验¦^°é变¶qªº¨ú­È¬O§_¤p¤_终­È¡C
For¡KNext语¥y结§ô¦Z会ªð¦^[¦^°é变¶q]ªº­È¡A¦ý¥¦¤@©w¤£µ¥¤_[终­È]:
Sub t()
Dim i
For i=1 to 10
Next
End  sub
³Ì¦Zi¬O¦h¤Ö©O¡H¤£ºÞ¬O¦h¤Ö¡A¥¦¤@©w¤£¬O10¡G
Sub t1()
    Dim i, j
    For i = 1 To 10
        j = j + 1
        MsgBox "¨B长­È为1,²Ä" & j & "¦¸¦^°é[¦^°é变¶q]ªº­È:" & i
    Next
    MsgBox "¦^°é¦¸数:" & j & Chr(13) & "³Ì¦Z[¦^°é变¶q]ªº­È:" & i
End Sub

Sub t2()
    Dim i, j
    For i = 1 To 10 Step 1.6
        j = j + 1
        MsgBox "¨B长­È为1.5,²Ä" & j & "¦¸¦^°é[¦^°é变¶q]ªº­È:" & i
    Next
    MsgBox "¦^°é¦¸数:" & j & Chr(13) & "³Ì¦Z[¦^°é变¶q]ªº­È:" & i
End Sub
¦b¦^°éÊ^¤¤¤]¥i¥H§ï变[¦^°é变¶q]ªº­È¡A¦ý这会¨Ïµ{§Ç¥N码ªº阅读©M调试变±o«D±`§x难¡A¤@¯ë¤£´£­Ò这样°µ:
Sub t3()
    Dim i, j
    For i = 1 To 10
        i = i + 1
        j = j + 1
        MsgBox "¨B长­È为1.5,²Ä" & j & "¦¸¦^°é[¦^°é变¶q]ªº­È:" & i
    Next
    MsgBox "¦^°é¦¸数:" & j & Chr(13) & "³Ì¦Z[¦^°é变¶q]ªº­È:" & i
End Sub

¦bFor¡KNext¦^°é¤¤¡A¥u­n¨B长¤£为0¡A´N¥Ã远¤£会¥X现¦º¦^°é¡C¦]为¥u­n¨B长¤£为0¡A无论©l­È©M终­È¤§间¬Û®t¦h¤\¤j¡A总¥i¥H经过¦³­­¦¸ªº¦^°é¡A¨Ï©l­È¶W¥X终­È¡A从¦Ó¸õ¥X¦^°é¡C¥Ñ¦¹¥i见¡AFor¡KNextÓì¥Î¤_预¥ýª¾¹D¦^°é¦¸数ªº±¡况¡C
¦b¬Y¨Ç±¡况¤U¡A¥i¯à»Ý­n¦b¦^°é变¶q没¦³¶W¥X终­È¤§«e´N¸õ¥X¦^°é¡A这时¥i¥H¥ÎExit For语¥y¡A当满¨¬¬YÏú¯S®íªº条¥ó时¡A´N´£«e¸õ¥X¦^°é¡C

从For¡KNext语¥yªº®æ¦¡¤¤¥i¥H¬Ý¨ì¡G¨ä¤¤ªº¦^°éÊ^¬O¥i选ªº¡C­Y¬Ù²¤¤F¦^°éÊ^¡A§YFor¦^°éªº¦^°éÊ^内没¦³¥ô¦ó¨ãÊ^ªº语¥y¡A则¨ä¥u¬O°_¨ì©µ时ªº§@¥Î¡C¦]为当¦^°é¤F¤@©w¦¸数¦Z虽¤£执¦æ¥ô¦ó¾Þ§@¡A¦ý却ªá费¤F¤@©w时间¡A¬G¥i§@为©µ时¤u¨ã¨Ï¥Î¡C¦ý­nª`·Nªº¬O¥Ñ¤_现¦b计ºâÉ󪺳t«×³£¤ñ较§Ö¤F¡A¦pªG¦^°é¦¸数¤ñ较¤Öªº话将¤£会达¨ì预´Áªº®ÄªG¡A¦]¦¹­nÓì当选择¦^°é¦¸数¡C

2.For Each¡KNext语¥y
FOR¡K¡KNext语¥yÉOFor¡KNext语¥y¦³¨Ç类¦ü¡A¦ý¥¦们¦³«Ü¤jªº区别¡G«eªÌ¬O¥Ñ«ü©w©Î¶°¦X¤¤ªº¤¸¯À来±±¨î¦^°é¡A¦Ó¦ZªÌ¬O¥Ñ¦^°é变¶q来±±¨î¦^°é过µ{¡C¥Ñ¦¹¥i见¡AFor Each¡K语¥y¬O¤£»Ý­n预¥ýª¾¹D¦^°é¦¸数ªº¡A«ü©w数组©Î¶°¦X¤¤ªº¤¸¯À个数´N¬O¦^°é¦¸数¡C该语¥yªº¨Ï¥Î®æ¦¡为¡G
    For Each¦^°é变¶qIn数组©Î¶°¦X
        ¦^°éÊ^
    Next¦^°é变¶q
    这¨½ªº¦^°é变¶q¥²须¬O变Ê^«¬(Variant)©Î对¶H«¬(Object)ªº¡C对¤_数组¡A¦^°é变¶q¥²须¬O变Ê^«¬ªº¡F对¤_¶°¦X¡A¦pªG¶°¦X¤¤¥]§t对¶H¡A则¦^°é变¶q应该¬O对¶H«¬¡A当µM¤]¥i¥H¬O变Ê^«¬¡C
当¬Y¤@数组©Î¶°¦X¨½ªº©Ò¦³¤¸¯À进¦æ¦P¤@¾Þ§@时¡A´N»Ý­n¨Ï¥Î该语¥y¤F¡C
¦P样ªº¥i¥H¥ÎExit For语¥y¡A当满¨¬¬YÏú¯S®íªº条¥ó时¡A´N´£«e¸õ¥X¦^°é¡C

For Each¡KNext语¥y结§ô¦Z¡A¤£会ªð¦^[¦^°é变¶q]¡A这ÉOFor¡KNext语¥y¤£¤@样:
Sub t4()
    Dim c
    For Each c In Array(1, 2, "aa")
    Next
    MsgBox TypeName(c)
End Sub
Sub t5()
    Dim r As Range
    For Each r In [a1:a4]
    Next
    MsgBox TypeName(r)
End Sub

3.Do¡KLoop语¥y
    Do¡KLoop¦^°é¬O®ÚÕu¬Y个条¥ó¬O§_¦¨¥ß来决©w¬O§_¦^°é¡C¥¦¦}¤£­­¨î¦^°éªº¦¸数¡A¥u­n满¨¬条¥ó´N继续¦^°é¡Aª½¨ì¤£满¨¬条¥ó时¸õ¥X¦^°é¡Cª`·N­n¦b¦^°é¤¤§ï变条¥ó¡A§_则ªº话¥i¯à会³´¤J¦º¦^°é¡C

    Do¡KLoop语¥y¦³¥|Ïú§Î¦¡¡G
§Î¦¡1¡G
DO
¦^°éÊ^
Loop While 条¥ó
这Ïú§Î¦¡ªº执¦æ过µ{¬O¡G¥ý执¦æ¤@¹M¦^°éÊ^¡AµM¦Z¦A§P断条¥ó¬O§_¦¨¥ß¡A­Y条¥ó¦¨¥ß¡A 继续¤U¤@¦¸¦^°é¡F§_则¡A´N°h¥X¦^°é¡C

§Î¦¡2¡G
Do While 条¥ó
¦^°éÊ^
Loop
这Ïú§Î¦¡¬O§â¡§While条¥ó¡¨©ñ¦b¦^°éÊ^ªº«e­±¡A¤]´N¬O说¥¦ªº执¦æ过µ{¬O¥ý§P断条¥ó¬O¥ß¡A¦A决©w¬O§_继续¦^°é¡C

§Î¦¡3¡G
DO
¦^°éÊ^
Loop Until 条¥ó
这Ïú§Î¦¡©M²Ä¤@Ïú§Î¦¡¦³¨Ç类¦ü¡A¤]¬O¥ý执¦æ¦^°éÊ^¡AµM¦Z¦A§P断条¥ó¡CÉO²Ä¤@Ïú§Î¦¡¤£¦P¡A这Ïú§Î¦¡¥u¦³当条¥ó¤£¦¨¥ß¤~会继续¦^°é¡A§_则´N°h¥X¦^°é¡C

§Î¦¡4¡G
DO Until 条¥ó
¦^°éÊ^
Loop
这Ïú§Î¦¡©M²Ä¤GÏú§Î¦¡¦³¨Ç类¦ü¡A¥ý§P断条¥ó¡A¦A决©w¬O§_继续¦^°é¡CÉO¤§¤£¦Pªº¬O¡A这Ïú§Î¦¡¤]¬O当条¥ó¤£¦¨¥ß¤~会继续¦^°é¡C

¥Ñ¤W­±¥|Ïú§Î¦¡ªº®æ¦¡¥i¥H¬Ý¥X¡G
    ²Ä¤@Ïú©M²Ä¤TÏú§Î¦¡¬O¥ý执¦æ¦^°éÊ^¡AµM¦Z¦A§P断条¥ó¡A条¥ó¦¨¥ßÉO§_¡A¦Ü¤Ö执¦æ¤@¦¸¦^°éÊ^¡F²Ä¤GÏú©M²Ä¥|Ïú§Î¦¡¡A则¬O¥ý§P断条¥ó¡A¦pªG条¥ó当¡A¦^°éÊ^¥i¯à¤@¦¸¤]没¦³执¦æ¡C¥B¡§While¡¨©M¡§Until¡¨¥¿¦n¬Û¤Ï¡A«eªÌ¬O条¥ó¦¨¥ß时¤J¦^°é¡A¦Ó¦ZªÌ则¬O条¥ó¤£¦¨¥ß时¤~进¤J¦^°é¡C¨Ï¥Î时¥i®ÚÕu»Ý­n选择³ÌÓì当ªº§Î¦¡¡C

    ¦b«e­±For¡KNext语¥y¤¤¤¶绍ªºExit语¥y¤]Óì¥Î¤_DO¡KLoop语¥y¡A¥u¬O§â¡§Exit For¡¨§ï¦¨¡§Exit Do¡¨§Y¥i¡A¥¦们ªº§@¥Î¬O¤@样ªº¡A³£¬O¥Î来´£«e¸õ¥X¦^°éªº¡C

资®Æ来·½:·L软帮§U

TOP

¦^´_ 4# Adela
¦p2¼Ó ªºSHEET2 Âà¦^¬°SHEET1®æ¦¡ ¶Ü ¦ýµLªkÂà¦^¦p­ì¨ÓªºSHEET1¤º®e
¸Õ¸Õ¬Ý
  1. Sub Ex()
  2. Dim Rng As Range, Ar(), E As Range, i%
  3. With Sheet2
  4.     Set Rng = .Range(.[A2], .[A65536].End(xlUp))
  5.     ReDim Ar(1 To Rng.Count)
  6.     For i = 1 To UBound(Ar)
  7.         Ar(i) = Array(Split(Rng(i), "-")(1), Split(Rng(i), "-")(0), Rng(i, 2))
  8.     Next
  9. End With
  10. With Sheet1
  11. .Columns("A:C") = ""
  12. .[A1].Resize(UBound(Ar), 3) = Application.Transpose(Application.Transpose(Ar))
  13. End With
  14. End Sub
½Æ»s¥N½X

TOP

        ÀR«ä¦Û¦b : µÊ®ð¼L¤Ú¤£¦n¡A¤ß¦a¦A¦n¤]¤£¯àºâ¬O¦n¤H¡C
ªð¦^¦Cªí ¤W¤@¥DÃD