我想删除 D 列中所有具有“+”和“-”的单元格。我尝试了以下宏,我认为它会起作用,但没有任何反应。
Sub doWhile4()
'Replace blank spaces with underscores in a Range of Cells, using VBA loops; or 'Remove
blank spaces in a Range of Cells, using VBA loops.
Dim iCell As Range
Dim textString As String
Dim n As Integer
'iCell is a Cell in the specified Range which contains the textString
'textString is the text in a Cell in which blank spaces are to be replaced with
'underscores. n is the position of blank space(s) occurring in a textString
For Each iCell In ActiveSheet.Range("D2:D34")
textString = iCell
n = InStr(textString, "+")
'The VBA InStr function returns the position of the first occurrence of a string within
'another string. Using this to determine the position of the first blank space in the
'textString.
Do While n > 0
textString = Left(textString, n - 1) & Right(textString, Len(textString) - n)
'This line of code is to remove all blank spaces in the
'textString
n = InStr(textString, "+")
Loop
iCell = textString
Next
End Sub
我究竟做错了什么?