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

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

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

ªñ¤é¦b¼g¤@¨ÇFUNCTION¨Ó³B²z¤å¦r¡A¥i¬O¹J¨ì¤£¤Ö§xÃø¡A½Ð¦U¦ìÀ°¦£¤@¤U¡G

¥Ø¼Ð¡G¼g¤@­Ó¥sWORDªºFUNCTION¡A®ÄªG¬O­n§ä¥X¦r¦ê¤¤¥Ø¼Ð¦r²´¡AÃþ¦üINSTR¡A¦ý¤£¦P¡C¨Ò¦p¡G
STR = "Now is the time"
word(str, 1)= Now
word(str, 2)= is
  1. Sub Word()
  2. Dim str As String
  3. Dim str_out As String
  4. Dim i As Integer, j As Integer, c As Integer, a As Integer

  5. str = "Now is the time"
  6. str = Trim(str)
  7. str_out = ""
  8. a = 3
  9. c = 0


  10. For i = 1 To Len(str)

  11.     If c = a - 1 Then
  12.         For j = i To Len(str)
  13.             If Mid(str, j, 1) <> " " Then
  14.                 str_out = str_out & Mid(str, j, 1)
  15.                 Else
  16.                 Exit For
  17.             End If
  18.         Next j
  19.         i = j
  20.         If InStr(Mid(str, j), " ") <> 0 Then
  21.             i = j
  22.             c = c + 1
  23.         Else
  24.             i = j
  25.         End If
  26.     End If
  27.    
  28.    
  29.     If Mid(str, i, 1) <> " " Then
  30.         For j = i To Len(str)
  31.             If InStr(Mid(str, j), " ") = 0 Then
  32.             i = Len(str)
  33.             ElseIf Mid(str, j, 1) = " " Then
  34.                 i = j
  35.                 Exit For
  36.             End If
  37.         Next j
  38.     c = c + 1
  39.     End If

  40. Next i
  41. MsgBox str_out
½Æ»s¥N½X
³o¬qCODE¬O¥i¥H³B²z¤å¦r¤§¶¡¥u¦³¤@­ÓªÅ®æªº¦r¦ê¡A¦ý¦p¦ó¦r¦êÅܦ¨¡G"Now is    the time"
³o­Ó«K¤£¦æ¤F¡A¤£ª¾¹D¦U¦ì¦³¨S¦³¤èªk¸Ñ¨M¡HÁÂÁ¤j®a

¦^´_  ¤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

¥»©«³Ì«á¥Ñ 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«È
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-28 09:48 ½s¿è

¦^´_ 9# ¤p«L«È
InStr(raw.Cells(i, 3), "¤p¾Ç")   ³o¥u·|¶Ç¦^¼Æ¦r
§A¦Û¦ê¤¤ ªì¤p, ¤p¾Ç,ªì¤¤, °ê¤¤.... ¨Ã¨S¦³©T©w¦b­þ­Ó¦ì¸m,¤£¾A¦X¥Î Select Case
  1. Select Case ÅܼƠ '
  2.       Case  ¼Æ¦r ©Î ¦r¦ê
  3. End Select
½Æ»s¥N½X

TOP

¦^´_  ¤p«L«È
GBKEE µoªí©ó 2012-8-27 20:26



    ³o­ÓW¬O­n¥Î
set w = raw.cells(i,3)
¨Ó³]©w¶Ü¡H
­ì¨Ó¦p¦¹¡AÁÂÁª©¤j

³o»ò¡A¬O¤£¬Oselect case¥u¯à¥Î¤@­Ócondition?

TOP

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

¦^´_ 7# ¤p«L«È
  1. If InStr(raw.Cells(i, 3), "¤p¾Ç") + InStr(raw.Cells(i, 3), "ªì¤p") > 0 Then  
  2.         '±ø¥ó : ¦p¤£¦¨¥ß, ·|§PÂ_¤U¤@­ÓElseIf±ø¥ó.¤@ª½¨ì¦³ElseIf±ø¥ó¦¨¥ß«á·|¤£¦A¥h§PÂ_¨ä¾lªº±ø¥ó,Â÷¶}¦¹ IF ....Then  ....Else  .....     End If
  3.         '¤£¥²   GoTo Define_unit
  4.         vbtype = "primary"                                                                                                            
  5.     ElseIf InStr(raw.Cells(i, 3), "ªì¤¤") + InStr(raw.Cells(i, 3), "°ê¤¤") + InStr(raw.Cells(i, 3), "°ª¤¤") > 0 Then
  6.         vbtype = "secondary"
  7.     ElseIf InStr(raw.Cells(i, 3), "¤j¾Ç") + InStr(raw.Cells(i, 3), "¤j±M") > 0 Then
  8.         vbtype = "Uni"
  9.     ElseIf InStr(raw.Cells(i, 3), "¬ã¨s©Ò") + InStr(raw.Cells(i, 3), "³Õ¤h") > 0 Then
  10.         vbtype = "Master+"
  11.     End If
  12.     If InStr((raw.Cells(i, 3), "¥xÆW") > 0 Then unit = "TW"
  13.     If InStr((raw.Cells(i, 3), "­»´ä") > 0 Then unit = "HK"
  14.     If InStr((raw.Cells(i, 3), "¬ü°ê") > 0 Then unit = "US"
½Æ»s¥N½X

TOP

¦^´_  ¤p«L«È
GBKEE µoªí©ó 2012-8-24 12:05

    §Ú¤]¥Î¹LREPLACE¡A¦ý·í³B²z¦h©ó¤@­ÓSPACE©Î¯S§O²Å¸¹®É´N·|¥X°ÝÃD¡A­ì¨Ó¥i¥H¥ÎSTRING + LOOPªº¤èªk
¨ü±Ð¤F¡C

¥t¥~¡A§Ú¥i¥H¦h°Ý¤@­Ó°ÝÃD¶Ü¡H¬OÃö©ó¤ÀªR¦r¦ê®É¦h±ø¥ó¿ï¾Üªº°ÝÃD
¨Ò¦p¡G§Ú­n¨ü³XªÌ¦^µª¥L¤l¤kªº¾Ç®Õ°Ï¤À©M¾Ç¾ú¡A¦pªG¨S¦³¤l¤k¡Aµª®×¯dªÅ¡AÂ൪¤U¤@ÃD
  1. If Ien(raw.Cells(i, 3)) > 0 Then
  2.     If InStr(raw.Cells(i, 3), "¤p¾Ç") + InStr(raw.Cells(i, 3), "ªì¤p") > 0 Then
  3.         type = "primary"
  4.         GoTo Define_unit
  5.     ElseIf InStr(raw.Cells(i, 3), "ªì¤¤") + InStr(raw.Cells(i, 3), "°ê¤¤")+ InStr(raw.Cells(i, 3), "°ª¤¤")  > 0 Then
  6.         type = "secondary"
  7.         GoTo Define_unit
  8.     ElseIf InStr(raw.Cells(i, 3), "¤j¾Ç") + InStr(raw.Cells(i, 3), "¤j±M")> 0 Then
  9.         type = "Uni"
  10.         GoTo Define_unit
  11.         
  12.     ElseIf InStr(raw.Cells(i, 3), "¬ã¨s©Ò") + InStr(raw.Cells(i, 3), "³Õ¤h") > 0 Then
  13.         type = "Master+"
  14.         GoTo Define_unit
  15.    
  16.     End If
  17.    
  18. Define_unit:
  19.         If InStr(raw.Cells(i, 3), "¥xÆW") > 0 Then unit = "TW"
  20.         If InStr(raw.Cells(i, 3), "­»´ä") > 0 Then unit = "HK"
  21.         If InStr(raw.Cells(i, 3), "¬ü°ê") > 0 Then unit = "US"
  22.     End If
½Æ»s¥N½X
¨Ò¦p¡Gµª®×¬O¡A§Ú¨à¤l¬O¦b¬ü°êŪ°ª¤¤
¨º»òunit = "US", TYPE=secondary

¦ý³o¸Ì¦³«Ü¦hIF THEN¡A¤S¤Óªø¡A¦³ÂI²V¶Ã¡C§Ú±N¤§§ï¥ÎGOTO¡A¤£¥Î­«½Æ¥X²{´X¦¸¬Û¦üªº¥y¤l¡C¦ý½Ð°Ý¥i¥H§ï¥Îselect case©Î¨ä¥L¤èªk²¤Æ¶Ü¡HÁÂÁÂ

TOP

¦^´_ 4# white945


    ¤Q¤À·PÁ¡A³o¬O¥¿§Ú»Ý­nªº¥\¯à

TOP

¥»©«³Ì«á¥Ñ GBKEE ©ó 2012-8-24 12:07 ½s¿è

¦^´_ 3# ¤p«L«È
  1. Option Explicit
  2. Sub Ex()
  3.     Dim TheWord As String, xW As String, E
  4.     xW = "a"
  5.     TheWord = "§Úaaaaa¬Oaaaaa¤@­Óaaaaaaaaa¨k¥Í"
  6.     Do
  7.         TheWord = Replace(TheWord, String(2, xW), xW)
  8.     Loop While InStr(TheWord, String(2, xW))  '= True
  9.     For Each E In Split(TheWord, xW)
  10.         MsgBox E
  11.     Next
  12. End Sub
½Æ»s¥N½X

TOP

        ÀR«ä¦Û¦b : §Ú­Ì³Ì¤jªº¼Ä¤H¤£¬O§O¤H¡D¥i¯à¬O¦Û¤v¡C
ªð¦^¦Cªí ¤W¤@¥DÃD