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

[µo°Ý] ¬O§_¦³§ó¾A¦X¦r¦êªº½s¿è­×§ï©O¡H

¥»©«³Ì«á¥Ñ dechiuan999 ©ó 2012-6-17 13:52 ½s¿è

ÁÂÁª©¥D¤j¤jªº«üÂI¡C
ª½±µ¨Ï¥ÎREPLACE¨ç¼Æ¥i´£¤É
¥\¯à©Ê¡C¨º¬O§_¦³¤èªk¥i¨Ï¥Î
·Æ¹«ª½±µ¿ï¨úTextbox1.Textªº¬Y¤@³sÄò¦r¦ê
¨Ã¾É¤J¦ÜTextbox2.text¦Ó¤£¥²¿é¤J
­n§ó´«ªº¦r¦ê©O¡H

¤U¦C¬O¤p§Ì¥t¤@²©öªºªí³æ

ComboBox1¡÷«ü©w­n´À´«¦r¦êªº¦¸¼Æ
Textbox1 ¡÷¥ÑÀx¦s®æ¶Ç¤Jªº¦r¦ê
Textbox2 ¡÷¯à§_¥Ñ·Æ¹«¿ï¨úTextbox1ªº¬Y¤@³sÄò¦r¦ê¨Ã¾É¤J¦ÜTextbox2©O¡H
Textbox3 ¡÷«ü©w­n§ó´«ªº¦r¦ê¡A¶·¥ÑÁä½L¿é¤J¦r¦ê

Private Sub CommandButton1_Click()
   
    Dim mTxt1$, mTxt2$, mTxt3$
    Dim C1%
   
    C1 = ComboBox1.Value    '«ü©w­n´À´«¦r¦êªº¦¸¼Æ
    mTxt1 = TextBox1.Text   '¥ÑÀx¦s®æ¶Ç¤Jªº¦r¦ê
    mTxt2 = TextBox2.Text   '¯à§_¥Ñ·Æ¹«¿ï¨úTextbox1ªº¬Y¤@³sÄò¦r¦ê¨Ã¾É¤J¦ÜTextbox2©O¡H
    mTxt3 = TextBox3.Text   '«ü©w­n§ó´«ªº¦r¦ê¡A¶·¥ÑÁä½L¿é¤J¦r¦ê
   
    mTxt1 = Replace(mTxt1, mTxt2, mTxt3, 1, C1, vbTextCompare)    'ª½±µ¤Þ¥ÎReplace¨ç¼Æ,逹¦¨½s¿è¡B­×§ï¡B§R°£¡B´À´«¡C
   
    TextBox1.Text = mTxt1
    Range("A1") = TextBox1.Text
   
   
End Sub

Private Sub UserForm_Initialize()
   
    TextBox1.Text = "ABCDEFG1234D5D6"
    With ComboBox1    '
        .AddItem "1"
        .AddItem "2"
        .AddItem "3"
        .Value = 1
    End With
   
End Sub

test.rar (6.99 KB)

TOP

¦^´_ 1# dechiuan999
¸Õ¸Õ  Replace ¨ç¼Æ  »P Replace ¤èªk  Application.WorksheetFunction.Replace ¦³ÂI¤£¤@¼Ë

Replace ¨ç¼Æ ¶Ç¦^¤@­Ó¦r¦ê¡A¸Ó¦r¦ê¤¤«ü©wªº¤l¦r¦ê¤w³Q¨ú¥N¦¨¥t¤@¤l¦r¦ê¡A¨Ã¥B¨ú¥Nµo¥Íªº¦¸¼Æ¤]¬O«ü©wªº¡C
»yªk   Replace(expression, find, replace[, start[, count[, compare]]])
Replace ¨ç¼Æ»yªk¦³¦p¤U´X­Ó«ü¦W¤Þ¼Æ¡G
³æ¤¸ ´y­z
expression ¥²­n¤Þ¼Æ¡C¦r¦ê¹Bºâ¦¡¡A¥]§t­n¨ú¥Nªº¤l¦r¦ê¡C
find ¥²­n¤Þ¼Æ¡C­n·j´M¨ìªº¤l¦r¦ê¡C
replace ¥²­n¤Þ¼Æ¡C¥Î¨Ó¨ú¥Nªº¤l¦r¦ê¡C
start ¿ï¾Ü©Ê¤Þ¼Æ¡C¦b¹Bºâ¦¡¤¤¤l¦r¦ê·j´Mªº¶}©l¦ì¸m¡C¦pªG©¿²¤¡A°²©w±q1¶}©l¡C
count ¿ï¾Ü©Ê¤Þ¼Æ¡C¤l¦r¦ê¶i¦æ¨ú¥Nªº¦¸¼Æ¡C¦pªG©¿²¤¡A¹w³]­È¬O ¡V1¡A¥¦ªí©ú¶i¦æ©Ò¦³¥i¯àªº¨ú¥N¡C
compare ¿ï¾Ü©Ê¤Þ¼Æ¡C¼Æ¦r­È¡Aªí¥Ü§P§O¤l¦r¦ê®É©Ò¥Îªº¤ñ¸û¼Ò¦¡¡CÃö©ó¨ä­È¡A½Ð°Ñ¾\¡u³]©w­È¡v¡C

TOP

        ÀR«ä¦Û¦b : ¸Ü¦h¤£¦p¸Ü¤Ö¡A¸Ü¤Ö¤£¦p¸Ü¦n¡C
ªð¦^¦Cªí ¤W¤@¥DÃD