- ©«¤l
- 4901
- ¥DÃD
- 44
- ºëµØ
- 24
- ¿n¤À
- 4916
- ÂI¦W
- 254
- §@·~¨t²Î
- Windows 7
- ³nÅ骩¥»
- Office 20xx
- ¾\ŪÅv
- 150
- ©Ê§O
- ¨k
- ¨Ó¦Û
- ¥x¥_
- µù¥U®É¶¡
- 2010-4-30
- ³Ì«áµn¿ý
- 2024-11-23
|
[Âà¶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
« ¦^ÂФ峹 #4 ©ó: 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
¦VªO¥DÀËÁ| 61.217.102.234 (?)
--------------------------------------------------------------------------------
µ²Ãf«Ý¼z§g
cjc
³X«È
Re: ½Ð°Ý¤£¦PÀɮתº¸ê®Æ½Æ»s
« ¦^ÂФ峹 #5 ©ó: 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?
ÁÂÁÂ!
¦VªO¥DÀËÁ| 61.229.1.159 (?)
yem
³X«È
Re: ½Ð°Ý¤£¦PÀɮתº¸ê®Æ½Æ»s
« ¦^ÂФ峹 #6 ©ó: 2005-04-12, 11:49:55 »
--------------------------------------------------------------------------------
¤Þ¥Î¦Û: 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´Nnµø¯u¥¿ªº¸ê®Æ§ïÅܽd³òªø«×¤F
¦VªO¥DÀËÁ| 218.175.222.56 (?)
cjc
³X«È
Re: ½Ð°Ý¤£¦PÀɮתº¸ê®Æ½Æ»s
« ¦^ÂФ峹 #7 ©ó: 2005-04-12, 12:52:36 »
--------------------------------------------------------------------------------
·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
« ¦^ÂФ峹 #8 ©ó: 2005-04-12, 13:38:48 »
--------------------------------------------------------------------------------
¤Þ¥Î¦Û: 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~k5n±qk1©¹¤U©Ô®@!!
¦VªO¥DÀËÁ| 218.175.222.56 (?)
leonchou
½×¾ÂºûÅ@¸s
Â÷½u
¤å³¹: 1214
Re: ½Ð°Ý¤£¦PÀɮתº¸ê®Æ½Æ»s
« ¦^ÂФ峹 #9 ©ó: 2005-04-12, 23:41:45 »
--------------------------------------------------------------------------------
¤Þ¥Î¦Û: 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ªGn»¡¥[¦³¤°»ò¦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
« ³Ì«á½s¿è®É¶¡: 2005-04-12, 23:46:32 ¥Ñ leonchou » ¦VªO¥DÀËÁ| 203.79.168.37 (?) |
|