如何设置一个Excel单元格的内容等于一个stringvariables?
我正在格式化一些我收到的数据。 我在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
我的问题是,如何设置我们正在循环到strStudentvariables的单元格的内容?
尝试这个
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
或者你不需要一个variables
With ThisWorkbook.Sheets("Sheet1") For x = 2 To 300 .Range("A" & x).Value = Replace(.Range("A" & x).Value, "*", "") Next End With