VB循环编程怎么弄啊A B C Daa Jack I am is aa,you is bb,cc is pig too...bb Mike you are aa,I am bb,pig is cc too...cc Yao she is aa,you is bb,cc is pig too.......要求把C列中的单元格里用公式将 aa bb cc.替换成 B列中的相对应

来源:学生作业帮助网 编辑:六六作业网 时间:2024/11/15 16:46:26
VB循环编程怎么弄啊ABCDaaJackIamisaa,youisbb,ccispigtoo...bbMikeyouareaa,Iambb,pigiscctoo...ccYaosheisaa,youi

VB循环编程怎么弄啊A B C Daa Jack I am is aa,you is bb,cc is pig too...bb Mike you are aa,I am bb,pig is cc too...cc Yao she is aa,you is bb,cc is pig too.......要求把C列中的单元格里用公式将 aa bb cc.替换成 B列中的相对应
VB循环编程怎么弄啊
A B C D
aa Jack I am is aa,you is bb,cc is pig too...
bb Mike you are aa,I am bb,pig is cc too...
cc Yao she is aa,you is bb,cc is pig too...
....
要求把C列中的单元格里用公式将 aa bb cc.替换成 B列中的相对应的内容,如aa替换成Jack,bb 代换成 Mike.
C列中每一个单元格要多次使用SUBSTITUTE替换.不是只替换一次.
唉.我已经折腾了三天了.没有结果.
要用VB循环编程.

VB循环编程怎么弄啊A B C Daa Jack I am is aa,you is bb,cc is pig too...bb Mike you are aa,I am bb,pig is cc too...cc Yao she is aa,you is bb,cc is pig too.......要求把C列中的单元格里用公式将 aa bb cc.替换成 B列中的相对应
怎么说呢,这里有个很简单的方法,就是用replace函数,你自己可以试下:

Dim a(1 To 3, 1 To 2) As String
Dim c(1 To 3) As String
Dim d(1 To 3) As String
Dim i As Integer
Dim j As Integer
a(1, 1) = "aa": a(1, 2) = "Jack"
a(2, 1) = "bb": a(2, 2) = "Mike"
a(3, 1) = "cc": a(3, 2) = "Yao"

c(1) = "I am is aa, you is bb, cc is pig too..."
c(2) = "you are aa, I am bb, pig is cc too..."
c(3) = "she is aa, you is bb, cc is pig too..."

For i = 1 To UBound(c)
d(i) = c(i)
For j = 1 To 3
d(i) = Replace(d(i), a(j, 1), a(j, 2))
Next
Debug.Print d(i)
Next


在这里我用的数组是固定维数的,如果无法确定数组上限时,就用动态数组吧,你自己再改下就行了

调试结果:
I am is Jack, you is Mike, Yao is pig too...
you are Jack, I am Mike, pig is Yao too...
she is Jack, you is Mike, Yao is pig too...