这里有一些代码有点问题。我想做三件事。我想跳过一个范围内的行,如果它包含“LINE:”,我想删除字符串中的任何尾随“ - ”,我想将任何正值转换为负值。下面是我的代码,但我遇到了麻烦。我在下面的行中收到“类型不匹配”错误。
ElseIf cellh.Value > 0 Then cellh.Value = cellh.Value * 1
我在想它是因为它试图评估一个范围而不是整数,但我需要能够引用范围以保持每个范围。任何帮助,将不胜感激。代码如下。谢谢!
Sub Test()
Dim rngh As Range, cellh As Range
Dim myString As String
Set rngh = Range("E1:E24")
For Each cellh In rngh
If Not InStr(cellh, "LINE:") > 0 Then
ElseIf InStr(cellh, "-") > 0 Then
myString = cellh.Text
myString = Left(myString, Len(myString) - 1)
cellh.Value = myString
ElseIf cellh.Value > 0 Then cellh.Value = cellh.Value * -1
End If
Next cellh
End Sub
LINE: 00005 <--Skip these lines
$12.29- <--Cut off trailing "-"
$2.59 <--Make a negative number
$13.56-
$2.59
LINE: 00006
$130.02-
LINE: 00007
$20.13-
$28.74-
LINE: 00008
$41.10-
$13.70-
LINE: 00009
$9.61-
LINE: 00010
$5.00-
$7.18-
LINE: 00011
$7.52-
$8.89-
LINE: 00012
$43.34-