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

[µo°Ý] ½Ð°Ý³z¹LVBAÂù¦V¬d¸ß¡A¦p¦ó°Ï§O­^¤å¤j¤p¼g?¡A¤]´N¬O¦r­n§¹¥þ¤@¼Ë

[µo°Ý] ½Ð°Ý³z¹LVBAÂù¦V¬d¸ß¡A¦p¦ó°Ï§O­^¤å¤j¤p¼g?¡A¤]´N¬O¦r­n§¹¥þ¤@¼Ë

¦p¹Ï¤ÎªþÀɤ¤¡A¦bÀx¦s®æC5¤ÎC6¶¡¶i¦æÂù¦V¬d¸ß¡A¦ý¥u­n¹J¨ì¦³¤j¤p¼g®É¡A¤£ºÞ¬O¥ý¤j¼gÁÙ¬O¥ý¤p¼g¡A²Ä¤@¦¸¬d¸ß§¹«á±ý¦A¬d¸ß²Ä¤G¦¸®É¡A´N¤£¯à¬d¸ß¡A½Ð°Ý¦U¦ì°ª¤â¦p¦óÅý¥¦§P§O¤j¤p¼g¡AÁÂÁ±z!

Âù¦V¬d¸ß.rar (14.98 KB)

VBAµ{¦¡¡G
Private Sub Worksheet_Change(ByVal Target As Range)
Dim A As Range
If Intersect(Target, [C5:C6]) Is Nothing Then Exit Sub
Application.EnableEvents = False
Set A = Columns("A:B").Find(Target, lookat:=xlWhole)
If A Is Nothing Then MsgBox
[C5] = Cells(A.Row, 1).Value
[C6] = Cells(A.Row, 2)
10
Application.EnableEvents = True
End Sub
peter460191

¥»©«³Ì«á¥Ñ GBKEE ©ó 2013-5-31 10:29 ½s¿è

¦^´_ 1# peter460191
VBA ªº»¡©ú
  1. Find ¤èªk
  2. ®M¥Î¦Ü Range ª«¥ó®É¥Î Find ¤èªk¡C
  3. ¦b½d³ò¤º´M§ä¯S©w¸ê°T¡A¨Ã¶Ç¦^ Range ª«¥ó¡A¸Óª«¥ó¥Nªí©Ò§ä¨ìªº²Ä¤@­Ó¥]§t©Ò´M§ä¸ê°TªºÀx¦s®æ¡C¦pªG¥¼µo²{²Å¦XªºÀx¦s®æ¡A´N¶Ç¦^ Nothing¡C¥»¤èªk¤£¼vÅT«ü©w½d³ò©Î¥Ø«eÀx¦s®æ¡C
  4. Ãö©ó¦b Visual Basic ¤¤¨Ï¥Î Find ¤u§@ªí¨ç¼Æªº¸Ô²Ó¤º®e¡A½Ð°Ñ¾\¦b Visual Basic ¤¤¨Ï¥Î Microsoft Excel ¤u§@ªí¨ç¼Æ¡C
  5. expression.Find(What, After, LookIn, LookAt, SearchOrder, SearchDirection, MatchCase, MatchByte, SearchFormat)
  6. expression      ¥²¿ï¡C¶Ç¦^ Range  ª«¥óªº¹Bºâ¦¡¡C
  7. What     ¥²¿ïªº Variant¡C  ­n´M§äªº¸ê®Æ¡C¥i¬°¦r¦ê©Î¥ô·N Microsoft Excel ¸ê®Æ«¬¦¡¡C
  8. After     ¿ï¾Ü©Êªº Variant¡C  «ü©wÀx¦s®æ¡A´M§ä±N±q¸ÓÀx¦s®æ¤§«á¶}©l¡C¦¹Àx¦s®æ¹ïÀ³©ó±q¨Ï¥ÎªÌ¤¶­±´M§ä®Éªº¨Ï¥Î¤¤Àx¦s®æ¦ì¸m¡Cª`·N After ¥²¶·¬O´M§ä½d³ò¤¤ªº³æ­ÓÀx¦s®æ¡C½Ð°O¦í´M§ä¬O±q¸ÓÀx¦s®æ¤§«á   ¶}©lªº¡F¥²¶·µ¥¨ì¸Ó¤èªk´`Àô¦^¨ì¦¹Àx¦s®æ®É¡A¤~·|·j´M¨ä¤º®e¡C¦pªG¥¼«ü©w¦¹¤Þ¼Æ¡A·j´M±N±q½d³òªº¥ª¤W¨¤Àx¦s®æ¤§«á¶}©l¡C
  9. LookIn     ¿ï¾Ü©Êªº Variant¸ê®ÆÃþ«¬¡C¸ê°TªºÃþ«¬¡C
  10. LookAt      ¿ï¾Ü©Êªº Variant¡C¥i¬°¤U¦C XlLookAt ±`¼Æ¤§¤@¡GxlWhole ©Î xlPart¡C
  11. SearchOrder      ¿ï¾Ü©Êªº Variant¡C¥i¬°¤U¦C XlSearchOrder ±`¼Æ¤§¤@¡GxlByRows ©Î xlByColumns¡C
  12. SearchDirection     ¿ï¾Ü©Êªº XlSearchDirection ¸ê®ÆÃþ«¬¡C·j´Mªº¤è¦V¡C
  13. XlSearchDirection ¥i¥H¬O³o¨Ç XlSearchDirection ±`¼Æ¤§¤@¡C
  14. xlNext ¹w³]­È
  15. xlPrevious
  16. MatchCase     ¿ï¾Ü©Êªº Variant¡C­Y«ü©w¬° True¡A«h·j´M®É¤j¤p¼gµø¬°¬Û²§¡C¹w³]­È¬° False¡C
  17. MatchByte     ¿ï¾Ü©Êªº Variant¡C¶È¥Î©ó±z¿ï¾Ü©Î¦w¸ËªºÂù¦ì¤¸»y¨¥¤ä´©ª©¥»¡C­Y«ü©w¬° True¡A´N¨ÏÂù¦ì¤¸²Õ¦r¤¸¶È²Å¦XÂù¦ì¤¸²Õ¦r¤¸¡C­Y«ü©w¬° False¡A«hÂù¦ì¤¸²Õ¦r¤¸¥i²Å¦X¨äµ¥»ùªº³æ¦ì¤¸²Õ¦r¤¸¡C
  18. SearchFormat     ¿ï¾Ü©Êªº Variant¡C·j´Mªº®æ¦¡¡C
½Æ»s¥N½X
·P®¦ªº¤ß......(¦b³Â»¶®a±Ú°Q½×°Ï.¥Î¤ß¾Ç²ß·|¦³¶i¨Bªº)
¦ý¸ê·½µL­­,«á´©¦³­­,  ¤@¤Ñ1¤¸ªºÃÙ§U,¤H¤H¦³¯à¤O.

TOP

¦^´_ 2# GBKEE


    «D±`ÁÂÁÂGBKEE ª©¥Dªº«ü¾É¡A¤~²¨¾Ç²Lµu®É¶¡µLªk©úÁA²`¶øªº¤º®e¡A¤è«KÀ°§Ú§ï¦nµ{¦¡½X¥H§Q¬ã¨s¶Ü¡HÁÂÁ±z¤F!
peter460191

TOP

¥»©«³Ì«á¥Ñ stillfish00 ©ó 2013-5-31 10:23 ½s¿è

¦^´_ 3# peter460191
MatchCase ¿ï¥Î  Variant
        ¦pªG¬° True¡A«h·j´M®É·|±N¤j¤p¼gµø¬°¬Û²§¡C¹w³]­È¬° False¡C

³o­ÓÀ³¸Ó´£¥Ü«Ü©úÅã¤F¡A¦h¬Ý°Ñ¼Æ»¡©ú¤~¯à¬¡¥Î¡C
Set A = Columns("A:B").Find(Target, lookat:=xlWhole,MatchCase:=True)

TOP

¦^´_ 4# stillfish00


    ·PÁÂstillfish00«ü¾É¡A¤w¦¨¥\¤F¡A·|¥J²Ó¬ã¨sª©¥Dªº»¡©ú¡A¦A¤@¦¸ÁÂÁ¨â¦ìªº«ü¾É¡AÁÂÁ±z!
peter460191

TOP

¦^´_ 3# peter460191
4# stillfish00 ªº Set A = Columns("A:B").Find(Target, lookat:=xlWhole,MatchCase:=True) ¸Õ¸Õ¬Ý
1#»¡:²Ä¤@¦¸¬d¸ß§¹«á±ý¦A¬d¸ß²Ä¤G¦¸®É¡A´N¤£¯à¬d¸ß ,¬O¦ó·N!
·P®¦ªº¤ß......(¦b³Â»¶®a±Ú°Q½×°Ï.¥Î¤ß¾Ç²ß·|¦³¶i¨Bªº)
¦ý¸ê·½µL­­,«á´©¦³­­,  ¤@¤Ñ1¤¸ªºÃÙ§U,¤H¤H¦³¯à¤O.

TOP

¦^´_ 6# GBKEE


    1#»¡:²Ä¤@¦¸¬d¸ß§¹«á±ý¦A¬d¸ß²Ä¤G¦¸®É¡A´N¤£¯à¬d¸ß,¬O¦ó·N!
·N«ä¬O·íc5Àx¦s®æ¿ï¨ì¤j¤p¼g¨ä¤¤¤@­Ó®É,¦A¿ï¥t¤@­Ó´N¤£¯à°Ê¤F
peter460191

TOP

¦^´_ 7# peter460191
  1. Private Sub Worksheet_Change(ByVal Target As Range)
  2. Static Mystr$
  3. Dim A As Range
  4. If Intersect(Target, [C5:C6]) Is Nothing Then Exit Sub '[C5:C6]¬°¸ê®Æ¿é¤J¦ì¸m¡A¥i¥ô·N§ïÅÜ
  5. Application.EnableEvents = False
  6. Set A = Columns("A:B").Find(Target, lookat:=xlWhole, MatchCase:=True) 'A:B¬°¸ê®Æ¨Ó·½¦ì¸mÄæ¦ì¡A¥i¥ô·N§ïÅÜ
  7. If InStr(1, Mystr, Target, vbBinaryCompare) > 0 Then MsgBox "°Ï¤À¤j¤p¼g¡A¤w¬d¸ß¹L": GoTo 10 '°Ï¤À¤j¤p¼g
  8. 'If InStr(Mystr, Target) > 0 Then MsgBox "¤£¤À¤j¤p¼g¡A¤w¬d¸ß¹L": GoTo 10 '¤£¤À¤j¤p¼g
  9. If A Is Nothing Then MsgBox "¿é¤J¿ù»~": [C5:C6] = "": GoTo 10 '[C5:C6]¬°¸ê®Æ¿é¤J¦ì¸m¡A¥i¥ô·N§ïÅÜ
  10. [C5] = Cells(A.Row, 1).Value '[C5:C6]¬°¸ê®Æ¿é¤J¦ì¸m¡A¥i¥ô·N§ïÅÜ
  11. [C6] = Cells(A.Row, 2) '[C5:C6]¬°¸ê®Æ¿é¤J¦ì¸m¡A¥i¥ô·N§ïÅÜ
  12. If Target.Address = "$C$5" Then Mystr = Mystr & "," & Target
  13. 10
  14. Application.EnableEvents = True
  15. End Sub
½Æ»s¥N½X
¾Ç®üµL²P_¤£®¢¤U°Ý

TOP

¦^´_ 8# Hsieh


   ÁÂÁ Hsieh ª©¥Dªºµ{¦¡¡A±N¥J²Ó¬ã¨s¬Ý¬Ý¡A«D±`ÁÂÁ±z!
peter460191

TOP

        ÀR«ä¦Û¦b : ±o²z­nÄǤH¡A²zª½­n®ð©M¡C
ªð¦^¦Cªí ¤W¤@¥DÃD