Doã»ã»ã»Loop Untilã¹ãã¼ãã¡ã³ãï¼å¾å¤æï¼ Do ç¹°ãè¿ãå®è¡ããå¦ç Loop Until æ¡ä»¶å¼ ããµã³ãã«ã³ã¼ãã ãããã1ãã10ã¾ã§ã®åãè¨ç®ãã¾ãã ForNextæ4ï½èªååå¾ããæçµè¡ã¾ã§ããã°ã©ã ãç¹°ãè¿ã. ããã¨ã ä¸ã«ãã表ã¯ãç¹°ãè¿ãå¦çï¼è¡¨ã®è¡åä½ï¼ãã¨ã«â ã¨â¡ã®å¤åã表ãããã®ã§ãã ãã®å³è¡¨ãè¦ãªããå
é è¡ãããéä¸é£ã°ãã¦æçµè¡ã¾ã§ã®å¦çãæ´çããã¨ã以ä¸ã®ããã«ãªãã¾ãã r=2ï¼ç¹°ãè¿ãå¦ç1åç®ãå
é ã¬ã³ã¼ãï¼ã®ã¨ãã EXCEL VBAã§ã®ã«ã¼ãå¦çã¯ããFor Next ã»Do While Loopã»Do Until Loopã»Do Loop Whileããªã©ãè¤æ°ããã¾ãããã«ã¼ãå¦çã¯ããç¹å®ãªåæ°ãæ¡ä»¶ãä¸è´ããæã«ã«ã¼ãããæããã®ãä¸è¬çã§ãããããã§ç´¹ä»ãããExit Forã¨Exit Doããå©ç¨ããäºã§ãã«ã¼ãéä¸ã§ãã«ã¼ãããæããäºãã§ã㾠⦠ããã¾ã§ãi=1 to 10ã¨ç¹°ãè¿ãã®åæ°ãåãã£ã¦ããäºä¾ãç´¹ä»ã㦠⦠ã¼ãè¡åä½ã§é 次å¦çããã¾ããããã¦ãæå¾ã®è¡ã¾ã§åãå¦çãç¹°ãè¿ãå¦çãã¾ããããã®é使ãVBAã³ã¼ããForãNextæã§ãã ãã¯ãå®è¡å¾. ã«ã¼ãå¦çã§ä¸çªå±éºãªã®ãããããããç¡éã«ã¼ããã«é¥ãã¨ãããã¨ã§ããçµããã®ãªãã«ã¼ãå¦çããæãåºããã«æ°¸é ã¨å¦çãç¹°ãè¿ããã¨ã«ãªãã¾ãã EXCEL VBAã§ã¯ãåãå¦çãç¹°ãè¿ãã«ã¼ãå¦çãè¤æ°æãã¾ãããFor Next ã»Do While Loopã»Do Until Loopã»Do Loop Whileããªã©ãã«ã¼ãå
ã§å¦çå®è¡ããå
容ãç¹°ãè¿ãã«ã¼ãæ¡ä»¶ã«å¿ãã¦ä½¿ãæ¹ãæ§ã
ããã¾ããã«ã¼ãæ¡ä»¶ãå¦çå
容ãããå§ãã«ããå ´åã¨çµããã«ããå ´åãªã©ãå¦çæ¡ä»¶ã«å¿ ⦠Do ç¹°ãè¿ãå®è¡ããå¦ç Loop While æ¡ä»¶å¼. ä¸è¨ãµã³ãã«ããã°ã©ã ã®ãã¤ã³ãã¨ãã¦ã¯ãæçµè¡ã«å°éããã¾ã§"Selection.End(xlDown).Select"ãç¹°ãè¿ãå®è¡ãããæçµè¡ã«ãã©ãçã1ã¤åã«"Selection.End(xlDown).Select"ã§é¸æãããã»ã«ã表ã®æçµè¡ã¨ããå¤æãããã¦ããç¹ã§ãã ¦ä¸ããä¸çªå³ä¸ã®ç¯å²ãé¸æãããã¨ããå ´åãããã¾ãã å¦çç¯å²ãå°ãããã¦é«éåãç®çã¨ããããã©ãããã©ãã¾ã§ãå¦çããã®ããæ示ããå ´åãªã©ãç¨éã¨ãã¦æã ⦠Sample1ã®7è¡ç®ã®ã Exit Do ã㯠InputBox ã® [ãã£ã³ã»ã«ãã¿ã³] ã®ã¯ãªãã¯ã«å¯¾å¿ãã¾ãã [OKãã¿ã³ ] ã®ã¯ãªãã¯ã®å ´åã¯ã Do Loop ã¹ãã¼ãã¡ã³ãã®å®è¡å¾å¤æã使ç¨ããæ¥ä»ãå
¥åãããã¾ã§ç¹°ãè¿ãå¦çãè¡ãã¾ãã åãã¾ããã "ã¨ã©ã¼ã¡ãã»ã¼ã¸ã¯ãªãã¸ã§ã¯ãã¯ãã®ããããã£ã¾ãã¯ã¡ã½ããããµãã¼ããã¦ã ⦠ãã¼ã¿æ°ã«å¿ãã¦ãæçµè¡ã¾ã§ç¹°ãè¿ãæ¹æ³ãå¿
è¦ã§ãã ããã«ã¯ãã¼ã¿ã®æçµè¡ãåããã°è¯ãã®ã§ãã 幸ããªãã¨ã«ãvbaã«ã¯ãã¼ã¿ã®å
¥ã£ã¦ããæçµè¡ãåå¾ããæ¹æ³ãç¨æããã¦ãã¾ãã Excelã®è¡¨ã使ã£ã¦ä½ãã管çããã°ãè¡ã追å ãæ¿å
¥ããããã¯åé¤ããä½æ¥ãå¿
è¦ã«ãªãã¾ãããããªä½æ¥ãé¢åãªæãããã§ããããä»åã¯ãExcelVBAã§è¡ãåé¤ããæ¹æ³ã«ã¤ãã¦è§£èª¬ãã¾ãããã¯ãã使ã£ã¦ä½æ¥ãå¹çåãã¦ãã¾ãã¾ãããã ã¨ã¯ã»ã«ãã¯ãVBAã«ã¦ããã¼ãã«ã®æ¿å
¥ã§A1ããQ1åã®æçµè¡ã¾ã§ãé¸æç¯å²ãããã§ãããã¯ãè¨é²ãããã¨ããã以ä¸â æ§æãè¨é²ããã¾ããããç¾å¨ã®æçµè¡ã¾ã§ããåå¾ã§ããªãããã以ä¸â¡ã®éãæ§æå¤æ´ãã¦ã¿ã¾ãããããªãã ã¨ã¯ã»ã«vbaã§ãã©ãã©ã®çµè²»ç²¾ç®æ¸ãããã¼ã¿ãéãããã¯ãã®ä½ãæ¹ã«ã¤ãã¦è§£èª¬ããã¦ãã¾ããä»åã¯ãã¨ã¯ã»ã«vbaã§ç¹°ãè¿ãã使ã£ã¦ãã¼ã¿ã転è¨ããæ¹æ³ãã¾ããã®éã®2ã¤ã®ãã¤ã³ãã«ã¤ãã¦ã ⦠ãåå¾ããæ¹æ³ãç´¹ä»ãã¾ãã æçµè¡ãåå¾ããæ¹æ³ã¯æ§ã
ãªããã°ã§ç´¹ä»ããã¦ãã¾ãã ã¨ããããä¸è¬çã«ç´¹ä»ããã¦ããæ¹æ³ã ã¨ãæ£ããæçµè¡ãåå¾ã§ããªãå ´åãããã¾ã ⦠ããã¦ãããã i=10ã«ãªãã¾ã§ç¹°ãè¿ãã¾ãã ãã¯ãå®è¡å. æçµè¡ã®ä¸ã«ãã¼ã¿ãç»é²ãã offsetããããã£. ã¨ã¯ã»ã«ãã¯ãã»vbaå
¥éã®ç¬¬7åã¯ãç¹°ãè¿ãå¦çã§ããã¨ã¯ã»ã«ã使ã£ã¦ããã¨ãåããã¨ãä½åº¦ãç¹°ãè¿ãã¦å¦çãããã¨ãå¤ã
ããã¾ããç¹°ãè¿ãå¦çããã¹ã¿ã¼ãã¦ãåããã¨ãç¹°ãè¿ãã¨ããé人éçä½æ¥ãç¡ããã¾ãããï¼ ãã¼ã¿ã®æçµè¡ã«sumé¢æ°ã§åè¨ãæ¿å
¥ããæ¹æ³ãã¼ã¿ã®æçµè¡ã«sumé¢æ°ãæ¿å
¥ããæ¹æ³ã¯ããã¾ãã¾ãªæ¹æ³ãããã¾ãããªãã¹ãç°¡ç´ ã§ãå¯èªæ§ãè¯ãã³ã¼ãããç´¹ä»ãã¾ãããã¼ã¿ä¾aåã売ä¸æ¥ããbåãååa売ä¸ããcåãååb売ä¸ããdåãåå 失æããªãçºã®ã«ã¼ãã®åãæ¹. Do Loopã¨ã¯ç¹°ãè¿ãã¦å¦çï¼ã«ã¼ãå¦çï¼ãè¡ããã¨ãã§ããå½ä»¤ã§ãWhileã¨Untilã使ç¨ãã2種é¡ã®æ¹æ³ãããã¾ããWhileã使ãã¨ãæ¡ä»¶ãçï¼Trueï¼ã®éãç¹°ãè¿ãå¦çãè¡ãã¾ããUntilã使ãã¨ãæ¡ä»¶ãçï¼Trueï¼ã«ãªãã¾ã§ãç¹°ãè¿ãå¦çãè¡ãã¾ããéä¸ã§ã«ã¼ããæããã«ã¯ãExit Doã使ãã¾ã Excelã®ãã¼ã¿å¦çããã¯ãã§èªååãããã¨æã£ãããå¿
ãã¤ãã¦åãã®ããæçµè¡ã®èªååå¾ãã§ãããã¼ã¿ã®å¦çãã©ããªãã®ã§ãããã¾ãã¯ãã¼ã¿ãã©ãã¾ã§å
¥ã£ã¦ãããã確èªãã¦ãå¦çãå®è¡ããç¯å²ã決ããªãã¨ããã¾ããã ã§ã³ã®ç®¡çè
ã«ãã´ãªã¼ : ã¨ã¯ã»ã«ä¸ç´è
åã , ãã¯ãä¸ç´è
åã ã»ã«ã®æçµè¡ã¾ã§ç¹°ãè¿ãã¦ãããããæ¹ãæãã¦ãã ããã ... ããã®å°ãªãvbaç¥èã®ä¸ã§ã®è³ªåãªã®ã§ãè¦å½éãã ã£ãããã¸ãã ã£ããããããªãã(..) 質å1.ããããããããã°ã§ããããï¼ï¼ã¨æã£ã¦ããã®ã§ã¯ã§ããªããã§ããããï¼ HOME > ã¬ãã«ã¢ãã > 失æããªãçºã®ã«ã¼ãã®åãæ¹. æçµè¡ãåå¾ãã¦ãããã«ãã¼ã¿ã追å ãã¦ãæçµè¡ã«ä¸æ¸ãããããã¾ããããã¼ã¿ãããè¡ã®ä¸ã«è¿½å ãã¦ãããªãã¨ãããªãã®ã§ãã.Cells(Rows.Count, 1).End(xlUp)ã«offset(1,0)ã追å ãã¾ãããã ã¼ãã®éå§è¡ãè¡æ°ã®å¤æ´ããã£ã¦ãç¹°ãè¿ãå¦çãã¡ããã¨åãããã°ã©ã ã®ä½ã ⦠Range ("A65536").End(xlUp). Sub æçµè¡ã¾ã§ç¹°ãè¿ã() 'â Dim i As Integer 'â¡ For i = 1 To 10 '⢠ï¼ããã«ç¹°ãè¿ãããå¦çã³ã¼ãï¼ Next '⣠End Sub '⤠â ã¯ã³ã¼ãå
¨ä½ã®ã¿ã¤ãã«ã§ãã ãSubãã¨ã()ãã®éã«ä»»æã®ãã®ãå
¥åãã¾ãã ç¯å²ã¨ãã¦æå®ãã¾ãã ãªãããã®äºä¾ã§ã¯Aåã®æçµè¡ãåå¾ãã¦ãã¾ãã Sub Sample8 Dim cmax As Long cmax = Worksheets ("Sheet3").