我正在格式化收到的一些数据。我在 A 列中有几百个学生的名字,由于某种奇怪的原因,有一个随机的*
随机放置在名称中。我想以编程方式删除所有*
所有名字中的字符。
For x = 2 To 300
Dim strStudent as String
//how do i set contents of cell to string strStudent
strStudent = Replace(strStudent, "*", "") //replace * with nothing
Next
我的问题是,如何将单元格的内容设置为 strStudent?然后我可以测试我的替换部分是否正确。
您不需要循环遍历单元格。您可以使用 Excel 的内置.Replace
替换全部功能*
通过使用"~*"
这是一个例子
Option Explicit
Sub Sample()
Dim ws As Worksheet
Dim Rng As Range
'~~> Change this to the relevant worksheet
Set ws = ThisWorkbook.Sheets("Sheet1")
'~~> Change this to the relevant range
Set Rng = ws.Range("A2:A300")
Rng.Replace What:="~*", Replacement:="", LookAt:=xlPart, SearchOrder _
:=xlByRows, MatchCase:=False, SearchFormat:=False, ReplaceFormat:=False
End Sub
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)