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
Excel 搜索缺少指定文本的单元格,然后添加它_Excel_Vba - Fatal编程技术网

Excel 搜索缺少指定文本的单元格,然后添加它

Excel 搜索缺少指定文本的单元格,然后添加它,excel,vba,Excel,Vba,我有一个Excel电子表格,A列有字母数字条目。所有条目都应该有相同的六位数结尾,但有些条目没有。我发现了一个宏,该宏将特定文本添加到列中每个单元格的末尾,但它将其添加到所有单元格。我试图调整的宏是: Sub AppendToExistingOnRight() Dim c As Range For Each c In Selection If c.Value <> "" Then c.Value = c.Value & "-368341" Next End Sub

我有一个Excel电子表格,A列有字母数字条目。所有条目都应该有相同的六位数结尾,但有些条目没有。我发现了一个宏,该宏将特定文本添加到列中每个单元格的末尾,但它将其添加到所有单元格。我试图调整的宏是:

Sub AppendToExistingOnRight()
 Dim c As Range
 For Each c In Selection
 If c.Value <> "" Then c.Value = c.Value & "-368341"
 Next
 End Sub
我只是不知道该用什么术语。我知道这可能很简单,但我已经搜索了一段时间,找不到简单的解决方案。请帮忙

请尝试:

If c.Value <> "" And InStr(c, "-368341") = 0 Then c.Value = c.Value & "-368341"  
如果c.值“”和InStr(c,“-368341”)=0,则c.值=c.值&“-368341”

而不是您的If声明。

谢谢您的提示……我对这一点还不熟悉
If c.Value <> "" And InStr(c, "-368341") = 0 Then c.Value = c.Value & "-368341"