Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/vba/15.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Vba 用通配符替换函数_Vba_Excel_Replace_Wildcard - Fatal编程技术网

Vba 用通配符替换函数

Vba 用通配符替换函数,vba,excel,replace,wildcard,Vba,Excel,Replace,Wildcard,目前,我开发了一个操作工具,用于比较DCS的复杂工程源文件。因此,我必须替换某些“标记名” For g = 8 To amountofreplace 'replace the string with every potential transition With Sheets("Compare") orgi = .range("L" & g).Value copy = .range("J" &

目前,我开发了一个操作工具,用于比较DCS的复杂工程源文件。因此,我必须替换某些“标记名”

    For g = 8 To amountofreplace 'replace the string with every potential transition
            With Sheets("Compare")
                orgi = .range("L" & g).Value
                copy = .range("J" & g).Value
                tmp_string = Replace(tmp_string, copy, orgi)
             End With
替换适用的代码:

    For g = 8 To amountofreplace 'replace the string with every potential transition
            With Sheets("Compare")
                orgi = .range("L" & g).Value
                copy = .range("J" & g).Value
                tmp_string = Replace(tmp_string, copy, orgi)
             End With
例如 tmp_串=200TT-50或200TX-50或200GG-50

    For g = 8 To amountofreplace 'replace the string with every potential transition
            With Sheets("Compare")
                orgi = .range("L" & g).Value
                copy = .range("J" & g).Value
                tmp_string = Replace(tmp_string, copy, orgi)
             End With
应转换为350TT-50或350TX-50或350GG-50

    For g = 8 To amountofreplace 'replace the string with every potential transition
            With Sheets("Compare")
                orgi = .range("L" & g).Value
                copy = .range("J" & g).Value
                tmp_string = Replace(tmp_string, copy, orgi)
             End With
所以现在我要添加过渡 200TT-->350TT 200TX-->350tx

    For g = 8 To amountofreplace 'replace the string with every potential transition
            With Sheets("Compare")
                orgi = .range("L" & g).Value
                copy = .range("J" & g).Value
                tmp_string = Replace(tmp_string, copy, orgi)
             End With
但我更喜欢的是应用这个过渡 200$$-->350$$

    For g = 8 To amountofreplace 'replace the string with every potential transition
            With Sheets("Compare")
                orgi = .range("L" & g).Value
                copy = .range("J" & g).Value
                tmp_string = Replace(tmp_string, copy, orgi)
             End With
$意味着一个字符[a-Z],因此当它被应用时,它将直接应用我上面提到的所有转换

    For g = 8 To amountofreplace 'replace the string with every potential transition
            With Sheets("Compare")
                orgi = .range("L" & g).Value
                copy = .range("J" & g).Value
                tmp_string = Replace(tmp_string, copy, orgi)
             End With
通配符不适用于替换函数。。谁有线索?因为我会一直填充不同的过渡。所以Regex对我来说似乎不是一个解决方案

    For g = 8 To amountofreplace 'replace the string with every potential transition
            With Sheets("Compare")
                orgi = .range("L" & g).Value
                copy = .range("J" & g).Value
                tmp_string = Replace(tmp_string, copy, orgi)
             End With
提前感谢,

您可以像中一样使用VBA.Left()

    For g = 8 To amountofreplace 'replace the string with every potential transition
            With Sheets("Compare")
                orgi = .range("L" & g).Value
                copy = .range("J" & g).Value
                tmp_string = Replace(tmp_string, copy, orgi)
             End With

为什么你认为正则表达式不适合你?实际上,您不能用它来更改大小写,但您可以找到小写字母,用
uCase()
来更改大小写,并像现在一样将其替换为原始字符串。(
tmp_string=Replace(tmp_string,RegExResult,uCase(RegExResult))
其中RegExResult是通过正则表达式搜索找到的小写字母)您的问题不清楚。替换(tmp_字符串,“200”,“350”,1,1)将把任何200$$更改为350$$,而不管$$是什么。忘记正则表达式吧——您甚至还没有解释为什么在Replace函数中需要通配符。扩展我之前的注释:对于长度至少为5的字符串,“应用转换200$-->350$$”和“应用转换200-->350$$”之间有什么区别?不过,我假设小写字母是一个打字错误