Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/string/5.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
String Excel VBA删除单元格中的字符串和以下行_String_Excel_Cell_Vba - Fatal编程技术网

String Excel VBA删除单元格中的字符串和以下行

String Excel VBA删除单元格中的字符串和以下行,string,excel,cell,vba,String,Excel,Cell,Vba,我需要从Excel中的多个单元格中删除某些字符串(例如“SUBJECT:”,此字符串后面有一个换行符),以及下面的整行,包括下一个换行符 如何为此编写宏 我猜是的 单元格。替换内容:=“主题:”&Chr(10)和“[任何文本]”&Chr(10),替换:=”,查看:=xlPart,SearchOrder:=xlByRows,MatchCase:=False,SearchFormat:=False,ReplaceFormat:=False您需要使用InStr: InStr([start],字符串,子

我需要从Excel中的多个单元格中删除某些字符串(例如“SUBJECT:”,此字符串后面有一个换行符),以及下面的整行,包括下一个换行符

如何为此编写宏

我猜是的


单元格。替换内容:=“主题:”&Chr(10)和“[任何文本]”&Chr(10),替换:=”,查看:=xlPart,SearchOrder:=xlByRows,MatchCase:=False,SearchFormat:=False,ReplaceFormat:=False
您需要使用InStr:

InStr([start],字符串,子字符串,[compare])

通过搜索“主题:”找到起点:

结束点是其后的第二个vbLf(换行符)字符,因此您希望在起始点加上第一个搜索字符串(8)的长度再加上一个:

endingPoint = Instr ( startingPoint + 8 + 1, cellValue, vbLf )
然后将其与Mid功能组合在一起:

中间(文本字符串、起始位置、长度)


长度将等于结束位置减去开始位置。

这在我的情况下有效

Selection.Replace What:="Subject:" & Chr(13) & "*" & Chr(13) & Chr(10), Replacement:="", Lookat:=xlPart, _
    SearchOrder:=xlByRows, MatchCase:=False, SearchFormat:=False, _
    ReplaceFormat:=False
Selection.Replace What:="Subject:" & Chr(13) & "*" & Chr(13) & Chr(10), Replacement:="", Lookat:=xlPart, _
    SearchOrder:=xlByRows, MatchCase:=False, SearchFormat:=False, _
    ReplaceFormat:=False