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

³B²zSTRING®É¹J¨ì§xÃø

¦^´_  ¤p«L«È
InStr(raw.Cells(i, 3), "¤p¾Ç")   ³o¥u·|¶Ç¦^¼Æ¦r
§A¦Û¦ê¤¤ ªì¤p, ¤p¾Ç,ªì¤¤, °ê¤¤....  ...
GBKEE µoªí©ó 2012-8-28 09:44



§Ú©¿µM·Q¨ì¡A¦pªG§Ú§â¤p¾Ç¡B¤¤¾Ç¡B¤j¾Ç¡B¬ã¨s¥Í¥H¤WªºÃþ§O¥ÎarrayÀx°_¨Ó¡A¥ÎFOR LOOP + select case ©Îif¬O¤£¬O¥i¥H¡H
¨Ò¦p¡G
  1. scl(1,1) = "ªì¤p"
  2. scl(1,2) = "¤p¾Ç"
  3. scl(2,1) = "ªì¤¤"
  4. scl(2,2) = "°ª¤¤"
  5. scl(3,1) = "¤j¾Ç"
  6. .
  7. .
  8. .

  9. edu(1)="¤p¾Ç"
  10. edu(2)="¤¤¾Ç"
  11. edu(3)="¤j¾Ç"
  12. .
  13. .

  14. for j = 1 to 4
  15.         for k = 1 to 2
  16.                 select case instr(raw.Cells(i, 3), scl(j,k))
  17.                         case >0
  18.                                 vbtype=edu(j)
  19.                 end select
  20.         next k
  21. next j
½Æ»s¥N½X
¦ý¦pªGsub¤¤©ñ¤F¤Ó¦hªºarray¡A·|¦³ÂI²V¶Ã¡A¦Ó¥BÃþ¦üªºarray¦b¨ä¥Lªºsub ¤]·|¥Î¨ì¡A¦pªG¦b¨C¤@­Ósub³£¦s¦³¬Û¦Pªºarray¡AºûÅ@®É¤]«Ü³Â·Ð¡A©Ò¥H§Ú¥´ºâ¥Îpublic const¥hdefine array¡A¦ý¥¢±Ñ¤F¡C

§Úªº°µªk¬O¡G

public dim scl(4,2) as string
const dim scl(1,1) = "ªì¤p"
const scl(1,2) = "¤p¾Ç"
.

sub abc()

¬O¤£¬O¤£¯à¦bpublic define 2dimensionalªº array¡H

TOP

¥»©«³Ì«á¥Ñ GBKEE ©ó 2012-8-29 13:09 ½s¿è

¦^´_ 11# ¤p«L«È
  1. Option Explicit
  2. Public scl, edu                  '¦¹¤½¥ÎÅÜ¼Æ ¥i¨Ñ¨ä¥Lµ{§Ç¨Ï¥Î   
  3. Private Sub Workbook_Open()  ' Workbook_Open ¬OThisWorkbook ¼Ò²Õªºµ{¦¡½X
  4.     ³]¥ß°}¦C
  5. End Sub
  6. Sub ³]¥ß°}¦C()  '¦b¦¹³]¥ß°}¦C ¥i¨Ñ¨ä¥Lµ{§Ç¨Ï¥Î   
  7.     ReDim scl(1 To 3, 1 To 2)
  8.     ReDim edu(1 To 3)
  9.     scl(1, 1) = "ªì¤p"
  10.     scl(1, 2) = "¤p¾Ç"
  11.     scl(2, 1) = "ªì¤¤"
  12.     scl(2, 2) = "°ê¤¤"
  13.     scl(3, 1) = "¤j¾Ç"
  14.     scl(3, 2) = "±M¬ì"
  15.     edu(1) = "¤p¾Ç"
  16.     edu(2) = "¤¤¾Ç"
  17.     edu(3) = "¤j¾Ç"
  18. End Sub
  19. Sub Ex()   '°õ¦æ "³]¥ß°}¦C" µ{§Ç«á¥i°õ¦æ¦¹µ{§Ç
  20.     Dim j, k, w, vbtype
  21.     w = "--°ê¤¤**"
  22.     For j = 1 To UBound(scl)
  23.         For k = 1 To UBound(scl, 2)
  24.            If InStr(w, scl(j, k)) Then vbtype = edu(j): GoTo Define_unit
  25.         Next k
  26.     Next j
  27. Define_unit:
  28.     MsgBox vbtype
  29. End Sub
½Æ»s¥N½X

TOP

¦^´_  ¤p«L«È
GBKEE µoªí©ó 2012-8-29 13:08



  ¼M¡I§Ú¦bºô¤W¥|³B§ä"excel vba public const array"¡A¥u¯à§ä¨ì1 dimension arrayªº³]©w¤èªk
­ì¨ÓÁÙ¦³³o¤@©Û¡A¤S¾Ç°_¨Ó¤F¡AÁÂÁª©¤j

TOP

        ÀR«ä¦Û¦b : ªY½à§O¤H´N¬O²øÄY¦Û¤v¡C
ªð¦^¦Cªí ¤W¤@¥DÃD