¿¿Æ×µç×ÓÊé > ¾­¹ÜÆäËûµç×ÓÊé > excel_vba_±à³Ì½Ì³Ì(ÍêÕû°æ) >

µÚ29²¿·Ö

excel_vba_±à³Ì½Ì³Ì(ÍêÕû°æ)-µÚ29²¿·Ö

С˵£º excel_vba_±à³Ì½Ì³Ì(ÍêÕû°æ) ×ÖÊý£º ÿҳ4000×Ö

°´¼üÅÌÉÏ·½Ïò¼ü ¡û »ò ¡ú ¿É¿ìËÙÉÏÏ·­Ò³£¬°´¼üÅÌÉ쵀 Enter ¼ü¿É»Øµ½±¾ÊéĿ¼ҳ£¬°´¼üÅÌÉÏ·½Ïò¼ü ¡ü ¿É»Øµ½±¾Ò³¶¥²¿£¡
¡ª¡ª¡ª¡ªÎ´ÔĶÁÍꣿ¼ÓÈëÊéÇ©ÒѱãÏ´μÌÐøÔĶÁ£¡



¾ßÓÐÁé»îÐÔ¡£ÕâÑù£¬ÄãµÄ×Ô¶¨Ò庯Êý¾ÍÄܹ»½«ÄãÌṩµÄÈκÎÁ½¸öÊýÖµ¼ÓºÍÆðÀ´ÁË¡£Ã¿¸ö±äÁ¿´ú±íÒ»¡¡
¸öÊýÖµ£¬ÄãÔÚÔËÐиú¯ÊýʱҪ¸øÿ¸ö±äÁ¿ÌṩÊýÖµ¡£¡¡¡¡
¼¼ÇÉ4£­3¡¡Ê¹Óú¯ÊýµÄÀíÓÉ¡¡¡¡
×Ô¶¨ÒåVBAº¯Êý¿ÉÒÔÓÃÓÚ£º¡¡¡¡
10¡£¡¡ÔÚPublic¡¡FunctionºÍEnd¡¡FunctionÖ®¼äÊäÈëÏÂÊöÓï¾ä£º¡¡¡¡
SumItUp¡¡=¡¡m¡¡£«¡¡n¡¡¡¡
ÕâÌõÓï¾äÒâ˼Êǽ«´¢´æÓÚ±äÁ¿nÉϵÄÊý¾Ý¼ÓÔÚ´¢´æÓÚ±äÁ¿mµÄÊýÖµÉÏ£¬²¢ÇÒ½«½á¹û·µ»Ø¸øº¯Êý¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡83¡¡

¡­¡¡Ò³Ãæ¡¡100¡­

SumItUp¡£ÔڵȺźóÃæÊäÈë¸Ãº¯ÊýÃû³Æ£¬ÔÙ¾ÍÊÇÀ¨ºÅºÍÐèÒª¼ÓºÍµÄÊýÖµ¡£ÔÚÉÏÃæµÄÓï¾äÖУ¬ÉèÖú¯¡¡
ÊýÃû³ÆµÈÓÚm¡¡£«¡¡nµÄºÍ¡£Íê³ÉµÄ×Ô¶¨Ò庯Êý¹ý³ÌÈçÏ£º¡¡¡¡
Public¡¡Function¡¡SumItUp£¨m£»n£©¡¡¡¡¡¡
¡¡¡¡¡¡¡¡¡¡¡¡¡¡SumItUp¡¡=¡¡m¡¡£«¡¡n¡¡¡¡¡¡
End¡¡Function¡¡¡¡¡¡
×£ºØ£¬ÄãÒѾ­´´½¨ÁËÄãµÄµÚÒ»¸öº¯Êý£¡È»¶ø£¬º¯Êý¹ý³Ì²¢Ã»ÓÐʲôÓ㬳ý·ÇÄãÖªµÀÈçºÎÖ´ÐÐËü¡£Ï¡¡
Ò»¸ö¶ÎÂ佫¸øÄãʾ·¶ÈçºÎʹÄãµÄº¯Êý¹¤×÷¡£¡¡¡¡

3¡£Ö´Ðк¯Êý¹ý³Ì¡¡¡¡

ÔÚµÚÒ»ÕÂÀÄãѧϰÁ˺ܶàÖз½·¨À´ÔËÐÐ×Ó³ÌÐò¡£ºÍ×Ó³ÌÐò²»Í¬£¬º¯Êý¹ý³ÌÖ»ÄÜʹÓÃÁ½ÖÖ·½·¨À´Ö´¡¡
ÐС£Äã¿ÉÒÔÓÃÓÚ¹¤×÷±íµÄ¹«Ê½ÀïÃ棬»òÕß´ÓÁíÍâÒ»¸ö¹ý³ÌÀïµ÷ÓÃËü¡£ÄãÔÚVBAÀï´´½¨µÄº¯Êý¹ý³Ì£¬¡¡
²»ÄÜͨ¹ýÔÚExcel´°¿ÚÑ¡Ôñ¡°¹¤¾ß¡±£­¡°ºê¡±£­¡°ÔËÐкꡱ·ÃÎÊ£»ËüÃÇÒ²²»ÄÜÔÚ´úÂëÀïÃæͨ¹ý°´F5¡¡
¼üÀ´ÔËÐС£½ÓÏÂÀ´µÄ²¿·ÖÀÄ㽫ѧϰµ½Ö´Ðк¯ÊýµÄרÃż¼Êõ¡£¡¡¡¡

4¡£´Ó¹¤×÷±íÀïÔËÐк¯Êý¹ý³Ì¡¡¡¡

×Ô¶¨Ò庯Êý¹ý³ÌºÍÄÚÖú¯ÊýÒ»Ñù£¬Èç¹ûÄã²»ÖªµÀÈ·Çеĺ¯ÊýÃû³Æ»òÕßËüµÄ×Ô±äÁ¿£¬ÄÇôÄã¿ÉÒÔʹÓá¡
¡¡¡°²åÈ뺯Êý¡±¶Ô»°¿òÀ´°ïÖúÄãÔÚ¹¤×÷±íÀïÊäÈëÐèÒªµÄº¯Êý¡£¡¡¡¡
1¡£¡¡¡¡Çл»µ½Excel´°¿Ú£¬²¢Ñ¡ÔñÈκÎÒ»¸öµ¥Ôª¸ñ¡¡¡¡
2¡£¡¡¡¡µã»÷º¯Êý¹¤¾ßÀ¸Éϵġ°²åÈ뺯Êý£¨fx£©¡±°´Å¥£¨ÒëÕߣº»òÕßÑ¡Ôñ¡°²åÈ롱£­¡°º¯Êý¡±£©£¬Excel¡¡
¡¡¡¡¡¡¡¡µ¯³ö²åÈ뺯Êý¶Ô»°¿ò£¬ÉÏÃæÏÔʾÁËËùÑ¡Àà±ðÀïËùÒÔº¯Êý£¬°´×Öĸ˳ÐòÅÅÁС¡¡¡
3¡£¡¡¡¡ÔÚÀà±ðÏÂÀ­¿òÀïÑ¡Ôñ¡°È«²¿¡±»òÕß¡°Óû§¶¨Ò塱£¬È»ºó¹ö¶¯º¯ÊýÃû³Æ¿ò£¬ÕÒµ½²¢Ñ¡Ôñ±¾ÕÂÖд´¡¡
¡¡¡¡¡¡¡¡½¨µÄº¯ÊýSumItUp¡£µ±ÄãÑ¡ÖÐÕâ¸öº¯ÊýÃû³Æʱ£¬ÔÚ²åÈ뺯Êý¶Ô»°¿òµÄϲ¿ÏÔʾÁ˸ú¯ÊýµÄÓï·¨£º¡¡
¡¡¡¡¡¡¡¡SumItUp£¨m£»n£©£¨ÒëÕߣºÍ¬Ê±¿ÉÒÔ¿´µ½¡°Ã»ÓаïÖúÐÅÏ¢¡±¡£Çë²ÎÔÄ´´½¨×Ô¶¨Ò庯ÊýµÄÏà¹Ø½Ì²Ä£¬¡¡
¡¡¡¡¡¡¡¡ÈçºÎ¸ø×Ô¶¨Ò庯ÊýÌṩ°ïÖúÐÅÏ¢£©¡¡¡¡
¼¼ÇÉ4£­4¡¡Ë½Óк¯ÊýÓû§ÊÇ¿´²»µ½µÄ¡¡¡¡
ʹÓùؼü×ÖPrivateÉùÃ÷µÄº¯Êý²»»á³öÏÖÔÚ¡°²åÈ뺯Êý¡±¶Ô»°¿òÉÏ£¬Ë½Óк¯Êý²»ÄÜÓÃÓÚ¹«Ê½ÀËü¡¡
ÃÇÖ»ÄÜ´ÓÁíÒ»¸öVBA¹ý³ÌÀïµ÷Óᣡ¡¡¡
¼¼ÇÉ4£­5¡¡¿ìËÙ·ÃÎÊ×Ô¶¨Ò庯Êý¡¡¡¡
Ò»µ©Äã´´½¨ÁËÒ»¸ö¹«¹²µÄVBAº¯Êý£¬Excel¾Í»á½«Ëü¼ÓÈëµ½¡°²åÈ뺯Êý¡±¶Ô»°¿òµÄ¡°Óû§¶¨Ò塱µÄÀà¡¡
±ðÀͨ¹ýÑ¡ÔñÕâ¸öÀà±ð£¬Äã¿ÉÒÔ¿ìËٵطÃÎʸÃ×Ô¶¨Ò庯Êý¡£¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡
ͼ4£­2¡¡VBA×Ô¶¨Ò庯Êý³öÏÖÔÚExcelÄÚÖú¯ÊýͬһÇåµ¥ÉÏ¡¡¡¡
4¡£¡¡¡¡µã»÷È·¶¨£¬¿ªÊ¼Ð´¹«Ê½¡£¡°º¯Êý²ÎÊý¡±¶Ô»°¿ò³öÏÖ£¬ÈçÏÂͼËùʾ¡£¶Ô»°¿òÏÔʾÁ˺¯ÊýÃû³ÆºÍÿ¡¡
¡¡¡¡¡¡¡¡¸ö²ÎÊý£ºmºÍn¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡84¡¡

¡­¡¡Ò³Ãæ¡¡101¡­

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡
ͼ4£­3¡¡¹«Ê½µÄµ÷É«°å¹¦ÄÜÓÐÖúÓÚÊäÈëÈκι¤×÷±íº¯Êý£¬²»ÂÛÊÇÄÚÖûòVBA±à³ÌµÄ×Ô¶¨Ò庯Êý¡¡¡¡
5¡£¡¡¡¡Èçͼ4£­3ËùʾÊäÈë×Ô±äÁ¿ÊýÖµ£¬»òÕßÄãÈÎÒâÊäÈëÊýÖµ¡£µ±ÄãÊäÈëÊýÖµÔÚ²ÎÊýÎı¾¿òʱ£¬Excel¡¡
¡¡¡¡¡¡¡¡ÏÔʾÄãÊäÈëµÄÊýºÍµ±Ç°µÄº¯Êý½á¹û¡£ÒòΪÁ½¸ö²ÎÊý£¨mºÍn£©¶¼ÊDZØÐëµÄ£¬ËùÒÔ£¬Èç¹ûÄãºöÂÔÁË¡¡
¡¡¡¡¡¡¡¡ÆäÖеÄij¸öʱ£¬º¯Êý»á·µ»Ø´íÎ󡣡¡¡¡
6¡£¡¡¡¡µã»÷È·¶¨Í˳öº¯Êý²ÎÊý¶Ô»°¿ò£¬ExcelÊäÈ뺯ÊýSumItUpÔÚËùÑ¡µÄµ¥Ôª¸ñÀ²¢ÇÒÏÔʾËüµÄ½á¹û¡£¡¡
¡¡¡¡¡¡¡¡Òª±à¼­Õâ¸ö¹«Ê½µÄ»°£¬Ñ¡Ôñ¸ÃÏÔʾ¹«Ê½½á¹ûµÄµ¥Ôª¸ñ£¬²¢ÇÒµã»÷¡°²åÈ뺯Êý¡±°´Å¥£¬Ñ¡Ôñº¯Êý¡¡
¡¡¡¡¡¡¡¡²¢µã»÷È·¶¨ÒÔ·ÃÎʺ¯Êý²ÎÊý¶Ô»°¿ò¡£ÔÚº¯Êý²ÎÊýmºÍnÉÏÊäÈ벻ͬµÄÊýÖµ£¬²¢µã»÷È·¶¨¡£Ò²¿ÉÒÔ¡¡
¡¡¡¡¡¡¡¡Ö±½ÓÔڸõ¥Ôª¸ñÉÏË«»÷£¬Ð޸ĺ¯Êý²ÎÊýÖµ¡£¡¡¡¡
¼¼ÇÉ4£­6¡¡È·±£ÄãµÄ×Ô¶¨Ò庯Êý¿ÉÓá¡¡¡
Ö»ÓÐÔÚÄã´¢´æ¸Ã×Ô¶¨Ò庯ÊýµÄ¹¤×÷²¾¿ªÆôµÄʱºò£¬ÄãµÄ×Ô¶¨ÒåVBAº¯Êý²Å¿ÉÓã¬Èç¹ûÄã¹Ø±Õ¸Ã¹¤×÷¡¡
²¾£¬¸Ãº¯Êý±ã²»ÔÙ¿ÉÓá£ÒªÈ·±£ÄãµÄ×Ô¶¨Ò庯Êýÿ´ÎÔÚÄãʹÓÃExcelʱ¶¼ÄÜÓõ½£¬Äã¿ÉÒÔ×öÏÂÊöÊ¡¡
ÇéÖ®Ò»£º¡¡¡¡

5¡£´ÓÁíÍâÒ»¸ö¡¡VBA¡¡¹ý³ÌÀïÔËÐк¯Êý¹ý³Ì¡¡¡¡

ÕýÈçÇ°ÃæÌáµ½µÄ£¬Äã²»ÄÜÔÚVB´°¿Ú½«¹â±ê·ÅÔÚ´úÂëÀï²¢ÇÒ°´F5À´ÔËÐк¯Êý£¬Ò²²»ÄÜͨ¹ýÑ¡Ôñ¡°ÔËÐС±¡¡
£­¡°ÔËÐкꡱÀ´ÔËÐк¯Êý¹ý³Ì¡£ÒªÔËÐк¯Êý£¬Äã±ØÐë´ÓÁíÍâÒ»¸ö¹ý³ÌÀïµ÷Óøú¯Êý¡£ÒªÖ´ÐÐ×Ô¶¨Òå¡¡
º¯Êý£¬±àдһ¸öVBA×Ó³ÌÐò²¢ÇÒÔÚÐèÒªµÄʱºòµ÷Óøú¯Êý¡£ÏÂÃæµÄ¹ý³Ìµ÷Óú¯ÊýSumItUp²¢ÇÒ½«¼ÆËã¡¡
½á¹ûÊä³öÔÚÁ¢¼´´°¿Ú£º¡¡¡¡
Sub¡¡RunSumItUp£¨£©¡¡¡¡¡¡
¡¡¡¡¡¡¡¡¡¡¡¡¡¡Dim¡¡m¡¡As¡¡Single£»¡¡n¡¡As¡¡Single¡¡¡¡¡¡
¡¡¡¡¡¡¡¡¡¡¡¡¡¡m¡¡=¡¡370000¡¡¡¡¡¡
¡¡¡¡¡¡¡¡¡¡¡¡¡¡n¡¡=¡¡3459¡£77¡¡¡¡¡¡
¡¡¡¡¡¡¡¡¡¡¡¡¡¡Debug¡£Print¡¡SumItUp£¨m£»n£©¡¡¡¡¡¡
¡¡¡¡¡¡¡¡¡¡¡¡¡¡MsgBox¡¡¡¨Open¡¡the¡¡Immediate¡¡window¡¡to¡¡see¡¡the¡¡result¡£¡¨¡¡¡¡¡¡
End¡¡Sub¡¡¡¡¡¡
¡¡¡¡¡¡¡¡m¡¡£«¡¡nÓï¾äÖ´ÐÐÍêºó£¬VB·µ»Øµ½×Ó¹ý³ÌRunSumItUpÀïÃ棬²¢ÇÒʹÓÃDebug¡£PrintÓï¾ä½«º¯ÊýµÄ½á¡¡
¡¡¡¡¡¡¡¡¹ûÊä³öÔÚÁ¢¼´´°¿Ú¡¡¡¡
ÒÀÕÕÏÂÊö²½ÖèÀ´ÊÔÑéÉÏÃæµÄÀý×Ó£º¡¡¡¡
1¡£¡¡¡¡ÔÚÊäÈ뺯ÊýSumItUpµÄͬһ¸öÄ£¿éÀïÃæÊäÈë¹ý³ÌRunSumItUp¡¡¡¡
2¡£¡¡¡¡½«¹â±ê·ÅÔڸùý³ÌµÄÈÎÒâµØ·½£¬°´ÏÂF5¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡85¡¡

¡­¡¡Ò³Ãæ¡¡102¡­

¼¼ÇÉ4£­7¡¡º¯ÊýµÄ¿ìËÙ²âÊÔ¡¡¡¡
Äã±àд×Ô¶¨Ò庯Êýºó£¬Äã¿ÉÒÔÔÚÁ¢¼´´°¿Ú¿ìËٵIJâÊÔËü¡£´ò¿ªÁ¢¼´´°¿Ú£¬ÊäÈëÒ»¸öÎʺţ¨£¿£©ÔÚº¯¡¡
ÊýÃû³ÆÇ°£¬¿ÉÒÔÏÔʾ¸Ãº¯ÊýµÄ¼ÆËã½á¹û¡£¼Çס£¬ÒªÔÚÀ¨ºÅÀïÊäÈ뺯ÊýµÄ²ÎÊýÖµ¡£¡¡ÀýÈ磬ÊäÈ룺¡¡¡¡
£¿¡¡SumItUp£¨54£»¡¡367¡£24£©¡¡¡¡
È»ºó»Ø³µ¡£ÄãµÄº¯ÊýʹÓòÎÊýmºÍn´«µÝµÄÊýÖµ½øÐмÆË㣬º¯ÊýµÄ½á¹ûÏÔʾÔÚÏÂÒ»ÐУº¡¡¡¡
421¡£24¡¡¡¡

6¡£´«µÝ²ÎÊý¡¡¡¡

µ½Ä¿Ç°ÎªÖ¹£¬ÄãÒѾ­´´½¨Á˼òµ¥µÄ¿ÉÒÔÖ´ÐоßÌåÈÎÎñµÄVBA¹ý³Ì£¬ÕâЩ¹ý³ÌÔÚËüÃÇÔËÐÐǰûÓÐÒªÇó¡¡
ÄãÌṩ¶îÍâµÄÊý¾Ý¡£È»¶ø£¬ÔÚÏÖʵÉú»îÖУ¬¹ý³Ì£¨×Ó³ÌÐòºÍº¯Êý£©¾­³£ÐèÒª²ÎÊý¡£²ÎÊý£¨×Ô±äÁ¿£©¡¡
Êǹý³Ì¹¤×÷ʱÐèÒªµÄÒ»¸ö»ò¶à¸öÊýÖµ¡£²ÎÊýͨ³£ÊäÈëÔÚÀ¨ºÅÖ®¼ä£¬¶à¸ö²ÎÊýÓöººÅ·Ö¸î¿ªÀ´¡£Ê¹Óá¡
ExcelÓÐÒ»ÕóÁË£¬ÄãÒѾ­ÖªµÀExcelÄÚÖú¯Êý¸ù¾ÝÄãÌṩµÄÊý¾Ý¿ÉÄܲúÉú²»Í¬µÄ½á¹û¡£ÀýÈ磬Èç¹ûµ¥¡¡
Ôª¸ñA4ºÍA5·Ö±ðº¬ÓÐÊý×Ö5ºÍ10£¬¼ÓºÍ¹«Ê½=SUM£¨A4£ºA5£©½«»á·µ»Ø15£¬³ý·ÇÄã¸ü¸Äµ¥Ôª¸ñÀïÃæµÄÊýÖµ¡£¡¡
ÕýÈçÄã¿ÉÒÔ´«µÝÊýÖµ¸øExcelÄÚÖú¯Êý£¬ÄãÒ²¿ÉÒÔ´«µÝÊýÖµ¸ø×Ô¶¨ÒåVBA¹ý³Ì¡£ÏÖÔÚ£¬ÎÒÃÇÀ´¿´¿´Èç¡¡
ºÎ´Ó×Ó³ÌÐò´«µÝÊýÖµ¸øº¯ÊýSumItUp¡£Õâ¸ö×Ô¶¨Ò庯ÊýÄ¿µÄÊǼÆËãÒ»¸öÈ˵ÄÐÕºÍÃûµÄ×ÖĸÊýÄ¿¡£¡¡¡¡
1¡£¡¡¡¡ÔÚ·ÅÖú¯ÊýSumItUpµÄÄ£¿éÀïÊäÈëÏÂÁÐ×Ó³ÌÐòNumOfCharacters£º¡¡¡¡
Sub¡¡NumOfCharacters£¨£©¡¡¡¡¡¡
¡¡¡¡¡¡¡¡¡¡¡¡¡¡Dim¡¡f¡¡As¡¡Integer¡¡¡¡¡¡
¡¡¡¡¡¡¡¡¡¡¡¡¡¡Dim¡¡l¡¡As¡¡Integer¡¡¡¡¡¡
¡¡¡¡¡¡¡¡¡¡¡¡¡¡f¡¡=¡¡Len£¨InputBox£¨¡¨Enter¡¡first¡¡name£º¡¨£©£©¡¡¡¡¡¡
¡¡¡¡¡¡¡¡¡¡¡¡¡¡l¡¡=¡¡Len£¨InputBox£¨¡¨Enter¡¡last¡¡name£º¡¨£©£©¡¡¡¡¡¡
¡¡¡¡¡¡¡¡¡¡¡¡¡¡MsgBox¡¡SumItUp£¨f£»l£©¡¡¡¡¡¡
End¡¡Sub¡¡¡¡¡¡
2¡£¡¡¡¡½«¹â±ê·ÅÔÚ¹ý³ÌNumOfCharactersµÄÈÎÒâµØ·½²¢°´ÏÂF5¡£VB½«ÏÔʾÐÅÏ¢ÊäÈë¿òÎÊÄãÃû×Ö£¬Õâ¸ö¡¡
¡¡¡¡¡¡¡¡ÐÅÏ¢¿òÓÉÏÂÃæµÄº¯Êý²úÉú£º¡¡¡¡
InputBox£¨¡¨Enter¡¡first¡¡name£º¡¨£©¡¡¡¡
3¡£¡¡¡¡ÊäÈëÈκÎÃû×Ö£¬»Ø³µ£¬VB½ÓÊÜÄãÊäÈëµÄÎı¾²¢ÇÒ½«Ëü×÷Ϊһ¸ö²ÎÊý´«µÝ¸øº¯ÊýLen¡£º¯ÊýLen¡¡
¡¡¡¡¡¡¡¡¼ÆËãÌṩµÄÎı¾µÄ×ÖĸÊýÄ¿¡£VB½«º¯ÊýLenµÄ½á¹û´¢´æÓÚ±äÁ¿fÒÔ¹©ÒÔºóʹÓá£ÕâÖ®ºó£¬VBÏÔʾ¡¡
¡¡¡¡¡¡¡¡ÏÂÒ»¸öÐÅÏ¢¿ò£¬Õâ´ÎÊÇÎÊÄãµÄÐÕ¡£¡¡¡¡
4¡£¡¡¡¡ÊäÈëÈκÎÐÕ£¬»Ø³µ¡£VB½«ÊäÈëµÄÐÕ´«µÝ¸øº¯ÊýLenÀ´»ñµÃÐÕµÄÎı¾³¤¶È£¬È»ºóÊýÖµ´¢´æÓÚ±äÁ¿l¡£¡¡
¡¡¡¡¡¡¡¡½ÓÏÂÀ´·¢ÉúʲôÄØ£¿VBÓöµ½Á˺¯ÊýMsgBox£¬Õâ¸öº¯Êý¸æËßVBÏÔʾº¯ÊýSumItUpµÄ½á¹û¡£È»¶ø£¬¡¡
¡¡¡¡¡¡¡¡ÒòΪÕâ¸ö½á¹û»¹Ã»ÓÐ×¼±¸ºÃ£¬VBºÜ¿ì¾ÍÌøµ½º¯ÊýSumItUpÀʹÓñäÁ¿fºÍl´¢´æµÄÊýÖµÀ´×ö¼Æ¡¡
¡¡¡¡¡¡¡¡Ëã¡£ÔÚº¯ÊýÄÚ²¿£¬VBÓñäÁ¿fµÄֵȡ´ú²ÎÊýmºÍ±äÁ¿lֵȡ´ú²ÎÊýn¡£Ò»µ©È¡´ú¹¤×÷Íê³É£¬VB½«Á½¡¡
¡¡¡¡¡¡¡¡¸öÊýÖµ¼ÓºÍÆðÀ´£¬²¢ÇÒ½«½á¹û·µ»Ø¸øº¯ÊýSumItUp¡£º¯ÊýSumItUpÄÚ²¿Ã»ÓÐÆäËüµÄÈÎÎñÁË£¬Òò´Ë£¬¡¡
¡¡¡¡¡¡¡¡VBÓÖÂíÉÏ·µ»Ø×Ó³ÌÐò²¢ÇÒ½«º¯ÊýSumItUpµÄ½á¹û×÷Ϊһ¸ö²ÎÊýÌṩ¸øº¯ÊýMsgBox¡£ÏÖÔÚÕâ¸öÐÅ¡¡
¡¡¡¡¡¡¡¡Ï¢³öÏÖÔÚÆÁÄ»ÉÏ£¬ÏÔʾÁË×Öĸ×ÜÊýÄ¿¡£¡¡¡¡
5¡£¡¡¡¡µã»÷È·¶¨Í˳öÐÅÏ¢¿ò£¬Äã¿ÉÒÔ¶à´ÎÔËÐйý³ÌNumOfCharacters£¬Ã¿´ÎÊäÈ벻ͬµÄÐÕÃû¡£¡¡¡¡
ÎÒÃÇÀ´¿´¿´ÁíÍâÒ»¸öʹÓñäÁ¿´«µÝ²ÎÊýµÄÀý×Ó£º¡¡¡¡
1¡£¡¡¡¡ÔÚ¹¤³ÌMyFunctions¡¡£¨Chap04¡£xls£©ÀïÌí¼ÓÒ»¸öÐÂÄ£¿é£¬²¢ÖØÃüÃûΪSample2¡¡¡¡
2¡£¡¡¡¡¼¤»îÄ£¿éSample2²¢ÇÒÊäÈë×Ó³ÌÐòEnterText£º¡¡¡¡
Sub¡¡EnterText£¨£©¡¡¡¡¡¡
¡¡¡¡¡¡¡¡¡¡¡¡¡¡Dim¡¡m¡¡As¡¡String£»¡¡n¡¡As¡¡String£»¡¡r¡¡As¡¡String¡¡¡¡¡¡
¡¡¡¡¡¡¡¡¡¡¡¡¡¡m¡¡=¡¡InputBox¡¡£¨¡¨Enter¡¡your¡¡first¡¡name£º¡¨£©¡¡¡¡¡¡
¡¡¡¡¡¡¡¡¡¡¡¡¡¡n¡¡=¡¡InputBox£¨¡¨Enter¡¡your¡¡last¡¡name£º¡¨£©¡¡¡¡¡¡
¡¡¡¡¡¡¡¡¡¡¡¡¡¡r¡¡=¡¡JoinText£¨m£»¡¡n£©¡¡¡¡¡¡
¡¡¡¡¡¡¡¡¡¡¡¡¡¡MsgBox¡¡r¡¡¡¡¡¡
End¡¡Sub¡¡¡¡
3¡£¡¡¡¡ÊäÈëÏÂÊöº¯Êý¹ý³Ì£º¡¡¡¡
Function¡¡JoinText£¨k£»o£©¡¡¡¡¡¡
¡¡¡¡¡¡¡¡¡¡¡¡¡¡JoinText¡¡=¡¡k¡¡£«¡¡¡¨¡¡¡¨¡¡£«¡¡o¡¡¡¡¡¡

¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡86¡¡

¡­¡¡Ò³Ãæ¡¡103¡­

End¡¡Function¡¡¡¡¡¡
4¡£¡¡¡¡ÔËÐйý³ÌEnterText¡¡¡¡
VBÖ´ÐÐÓï¾äʱ£¬ËüÊÕ¼¯Óû§ÊäÈëµÄÊý¾Ý²¢ÇÒ½«ÕâЩÊý¾Ý´¢´æÔÚ±äÁ¿mºÍnÉÏ£¬È»ºó´«µÝÕâЩÊý¾Ýµ½º¯¡¡
ÊýJoinText¡£VB½«ÕâЩ±äÁ¿µÄֵȡ´úº¯ÊýJoinTextµÄ²ÎÊý£¬²¢ÇÒ½«½á¹û¸³µ½º¯ÊýÃû³Æ£¨JoinText£©¡¡
ÉÏ¡£µ±VB·µ»Ø¹ý³ÌEnterTextʱ£¬º¯ÊýµÄÖµ´¢´æÓÚ±äÁ¿r¡£È»ºó£¬º¯ÊýMsgBoxÔÚÐÅÏ¢¿òÀïÏÔʾ±äÁ¿r¡¡
µÄÄÚÈÝ¡£½á¹û¾ÍÊÇÓû§µÄÍêÕûÐÕÃû£¨ÐÕºÍÃûÓÿոñ·Ö¿ª£©¡£Òª´Óº¯Êý´«µÝÊýÖµ¸ø×Ó³ÌÐò£¬ÐèÒª½«¸Ã¡¡
Öµ¸³µ½º¯ÊýÃû³Æ£¬ÀýÈ磬ÏÂÃæµÄº¯ÊýNumOfDays½«Öµ7´«µÝµ½×Ó³ÌÐòDaysInAWeek£º¡¡¡¡
Function¡¡NumOfDays£¨£©¡¡¡¡¡¡
¡¡¡¡¡¡¡¡¡¡¡¡¡¡NumOfDays¡¡=¡¡7¡¡¡¡¡¡
End¡¡Function¡¡¡¡¡¡
Sub¡¡DaysInAWeek£¨£©¡¡¡¡¡¡
¡¡¡¡¡¡¡¡¡¡¡¡¡¡MsgBox¡¡¡¨There¡¡are¡¡¡¨¡¡&¡¡NumOfDays¡¡&¡¡¡¨¡¡days¡¡in¡¡a¡¡week¡£¡¨¡¡¡¡¡¡
End¡¡Sub¡¡¡¡
¼¼ÇÉ4£­8¡¡º¯Êý¹ý³Ì²»ÄÜ×öʲô¡¡¡¡
º¯Êý¹ý³Ì²»ÄܽøÐÐÈκζ¯×÷£¬ÀýÈ磬ËüÃDz»ÄÜÔÚ¹¤×÷±íÀï×ö²åÈ룬ɾ³ý»òÉèÖÃÊý¾Ý¸ñʽ²Ù×÷£¬²»ÄÜ¡¡
´ò¿ªÎļþ£¬»ò¸Ä±äÆÁÄ»ÏÔʾÑùʽ¡¡¡¡

7¡£Ã÷È·²ÎÊýÀàÐÍ¡¡¡¡

ÔÚÇ°ÃæµÄ²¿·Ö£¬ÄãѧϰÁ˺¯Êý¸ù¾ÝËüÃÇ×Ô±äÁ¿´«µÝµÄÖµ½øÐмÆË㣬µ±ÄãÉùÃ÷º¯Êýʱ£¬Ä㽫²ÎÊýÃû³Æ¡¡
ÁÐÔÚÒ»¶ÔÀ¨ºÅÀïÃæ¡£²ÎÊýÃû³Æ¾ÍÏñ±äÁ¿Ò»Ñù£¬Ã¿¸ö²ÎÊýÃû³ÆÔÚº¯Êýµ÷ÓÃʱ£¬ÒýÓÃÄãÌṩµÄÊýÖµ¡£µ±¡¡
×Ó³ÌÐòµ÷Óú¯Êý¹ý³Ìʱ£¬ËüÒÔ±äÁ¿ÐÎʽ´«µÝ²ÎÊý¡£Ò»µ©º¯Êý×öµãʲô£¬Ëü¾Í½«½á¹û¸³¸øº¯ÊýÃû³Æ¡£¡¡
×¢Ò⣬º¯Êý¹ý³ÌµÄÃû³Æµ±×÷±äÁ¿À´Ê¹Óᣡ¡¡¡
Ïó±äÁ¿Ò»Ñù£¬º¯ÊýÒ²ÓÐÀàÐÍ£¬º¯ÊýµÄ½á¹û¿ÉÒÔÊÇ×Ö·û´®ÐÍ£¬ÕûÐÍ£¬³¤ÕûÐÍ£¬µÈ¡£ÒªÃ÷È·Ä㺯ÊýµÄ½á¡¡
¹ûÀàÐÍ£¬Ö»ÓÐÔÚº¯ÊýÉùÃ÷ÐкóÌí¼Ó¹Ø¼ü×ÖAsºÍÄãÏëÒªµÄÀàÐͼ´¿É¡£ÀýÈ磺¡¡¡¡
Function¡¡MultiplyIt£¨num1£»¡¡num2£©¡¡As¡¡Integer¡¡¡¡
Èç¹ûÄã²»Ã÷È·Êý¾ÝÀàÐÍ£¬VB½«°ÑÄãµÄº¯Êý½á¹ûÉèÖÃΪĬÈÏÀàÐÍ£¨VariantÊý¾ÝÀàÐÍ£©¡£µ±ÄãÃ÷È·ÄãµÄ¡¡
º¯Êý½á¹ûµÄÊý¾ÝÀàÐÍʱ£¬¾ÍÏóÄãÃ÷È·±äÁ¿µÄÊý¾ÝÀàÐÍÄÇÑùÓÐһЩºÃ´¦£¬ÄãµÄ³ÌÐò½«¸üÓÐЧµØʹÓÃÄÚ¡¡
´æ£¬Òò´ËËüÔËÐеÃÒ²¸ü¿ìЩ¡£¡¡¡¡
ÎÒÃÇÀ´¿´¿´Õâ¸öÀý×Ó£¬¾¡¹ÜÆä²ÎÊýÔÚÖ÷µ÷¹ý³ÌÉùÃ÷µÄÊǵ¥¾«¶È¸¡µãÐÍ£¬µ«ÊǺ¯ÊýÈÔÈ»·µ»ØÕûÐÍÊý¾Ý£º¡¡¡¡
1¡£¡¡¡¡ÔÚ¹¤³ÌMyFunctions¡¡£¨Chap04¡£xls£©ÀïÌí¼ÓÒ»¸öÐÂÄ£¿é£¬ÖØÃüÃûΪSample3¡¡¡¡
2¡£¡¡¡¡¼¤»îÄ£¿éSample3²¢ÇÒÊäÈë×Ó³ÌÐòHowMuch£¬ÈçÏÂËùʾ£º¡¡¡¡
Sub¡¡HowMuch£¨£©¡¡¡¡¡¡
¡¡¡¡¡¡¡¡¡¡Dim¡¡num1¡¡As¡¡Single¡¡¡¡¡¡
¡¡¡¡¡¡¡¡¡¡Dim¡¡num2¡¡As¡¡Single¡¡¡¡¡¡
¡¡¡¡¡¡¡¡¡¡Dim¡¡result¡¡As¡¡Single¡¡¡¡¡¡
¡¡¡¡¡¡¡¡¡¡num1¡¡=¡¡45¡£33¡¡¡¡¡¡
¡¡¡¡¡¡¡¡¡¡num2¡¡=¡¡19¡£24¡¡¡¡¡¡
¡¡¡¡¡¡¡¡¡¡result¡¡=¡¡MultiplyIt£¨num1£»¡¡num2£©¡¡¡¡¡¡
¡¡¡¡¡¡¡¡¡¡MsgBox¡¡result¡¡¡¡¡¡
End¡¡Sub¡¡¡¡¡¡
3¡£¡¡¡¡ÔÚ×Ó³ÌÐòHowMuchÏÂÃæÊäÈëÏÂÁк¯Êý¹ý³Ì£º¡¡¡¡
Function¡¡MultiplyIt£¨num1£»num2£©¡¡As¡¡Integer¡¡¡¡¡¡
¡¡¡¡¡¡¡¡¡¡MultiplyIt¡¡=¡¡num1¡¡*¡¡num2¡¡¡¡¡¡
End¡¡Function¡¡¡¡¡¡
ÒòΪ´¢´æÓÚ±äÁ¿num1ºÍnum2µÄÊýÖµ²»ÊÇÕûÊý£¬ÒªÈ·±£ËüÃÇÏà³ËºóµÄ½á¹ûΪÕûÊý£¬Äã¾ÍµÃ½«º¯Êý½á¹û¡¡
ÉèÖÃΪÕûÐÍ¡£Èç¹ûÄã²»¸øº¯ÊýMultiplyItµÄ½á¹ûÉèÖÃÊý¾ÝÀàÐÍ£¬¹ý³ÌHowMuch½«»á½«½á¹û°

·µ»ØĿ¼ ÉÏÒ»Ò³ ÏÂÒ»Ò³ »Øµ½¶¥²¿ ÔÞ£¨0£© ²È£¨0£©

Äã¿ÉÄÜϲ»¶µÄ