我正在格式化我收到的一些数据。我在 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 变量?
最佳答案
尝试这个
Dim strStudent As String
With ThisWorkbook.Sheets("Sheet1")
For x = 2 To 300
strStudent = Replace(.Range("A" & x).Value, "*", "") '//replace * with nothing
.Range("A" & x).Value = strStudent
Next
End With
或者,您不需要变量
With ThisWorkbook.Sheets("Sheet1")
For x = 2 To 300
.Range("A" & x).Value = Replace(.Range("A" & x).Value, "*", "")
Next
End With
关于excel - 如何将 Excel 单元格的内容设置为等于字符串变量?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20167254/