gpt4 book ai didi

Excel VBA - 删除某些字符串

转载 作者:行者123 更新时间:2023-12-04 22:09:25 26 4
gpt4 key购买 nike

我之前问过如何检查一段文本是否包含字符串,现在如果在该单元格中找到该字符串,我想删除它。

If the value in column C is different from column W, I check whether column A contains "MIG", if it does I add it to the cell, if not I do nothing.



因为每次保存时都会运行此宏,如果您要编辑 W 和 C 中的值以使其匹配,那么 A 列仍会显示“MIG”。

So when the document is saved, the macro will now see column C & W are the same and if it contains "MIG" it should delete "MIG" from the cell.



样本
If shtVO.Cells(Row, 3).Value <> shtVO.Cells(Row, 23).Value Then
If shtVO.Cells(Row, 1).Value Like "*MIG*" Then
Else
shtVO.Cells(Row, 1).Value = shtVO.Cells(Row, 1).Value + "MIG"
End If
Else
If shtVO.Cells(Row, 3).Value = shtVO.Cells(Row, 23).Value Then
If shtVO.Cells(Row, 1).Value Like "*MIG*" Then
.....
End If
End If
End If

最佳答案

不确定我是否理解您的逻辑,但要清除单元格值使用

shtVO.Cells( ... ).ClearContents

编辑

使用 Replace
shtVO.Cells( ... ).Value = Replace(shtVO.Cells( ... ).Value, "MIG", "")

您的其余评论涉及替换 MIG 后留下双倍空格的可能性。
例如 "Fisrt MIG second" --> "Fisrt  second"

关于Excel VBA - 删除某些字符串,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12366042/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com