Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/vba/16.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/extjs/3.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
Excel VBA如果A列中有值,则替换B列中的值_Excel_Vba_Find Replace - Fatal编程技术网

Excel VBA如果A列中有值,则替换B列中的值

Excel VBA如果A列中有值,则替换B列中的值,excel,vba,find-replace,Excel,Vba,Find Replace,im当前使用此VBA代码查看Sheet2中A列中的值,如果找到,则删除Sheet1中A列中的此值 Sub-ifFoundReplace() 尺寸i为长,ws1为工作表,ws2为工作表 设置ws2=图纸(“图纸2”) 设置ws1=图纸(“图纸1”) 对于i=2到ws2.Range(“A”&Rows.Count).End(3).row ws1.Columns(1).替换ws2.Cells(i,“A”)&“xlPart” ws1.Columns(1).替换“&ws2.Cells(i,“A”),”和“

im当前使用此VBA代码查看Sheet2中A列中的值,如果找到,则删除Sheet1中A列中的此值

Sub-ifFoundReplace()
尺寸i为长,ws1为工作表,ws2为工作表
设置ws2=图纸(“图纸2”)
设置ws1=图纸(“图纸1”)
对于i=2到ws2.Range(“A”&Rows.Count).End(3).row
ws1.Columns(1).替换ws2.Cells(i,“A”)&“xlPart”
ws1.Columns(1).替换“&ws2.Cells(i,“A”),”和“xlPart”
接下来我

End Sub
您可以使用正则表达式,它能够识别字符串周围是否有空格、行的开始或行的结束。像这样的

Dim regex As Object, str As String
Set regex = CreateObject("VBScript.RegExp")

With regex
  .Pattern = "(^|[[:blank:]])[" + :: VALUE FROM SHEET 1:: + "]($|[[:blank:]])"
  .Global = True
End With

val = ::value of cell you are evaluating::
newVal = regex.Replace(val , "")

然后把newVal放在你要计算的单元格中。我在工作,所以我不能测试这一点,但希望这能让你走上正确的道路

基本上,我想删除所有精确匹配,所以只有“a”。