[英]Excel VBA - Append cell by removing string
I am looking to append cells containing numbers and text so that the text is removed.我正在寻找附加包含数字和文本的单元格,以便删除文本。
Take 1.1 (Very Low)
as an example of what is in the cell.以
1.1 (Very Low)
为例说明单元格中的内容。
I would like to remove (Very Low)
from the cell.我想从单元格中删除
(Very Low)
。
I have figured out how to do this using InStr
.我已经想出了如何使用
InStr
来做到这一点。
I was trying to edit cells in a range by cycling through them whilst checking for a string.我试图通过在检查字符串时循环遍历它们来编辑范围内的单元格。 I would then remove the specified string.
然后我会删除指定的字符串。 You can do this by checking the cell for your string using
InStr
and then using Replace
to update the cell contents.为此,您可以使用
InStr
检查单元格中的字符串,然后使用Replace
更新单元格内容。
I found a way to do this using:我找到了一种方法来做到这一点:
Dim ws as Worksheet, rCell As Range, rArea As Range
Set rArea = ws.Range("A1:A10")
For Each rCell In rArea.Cells
If InStr(rCell.Value, " (Very Low)") Then
rCell.Value = Replace(rCell.Value, " (Very Low)", "")
End If
Next rCell
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.