忽略特殊字符

问题描述 投票:0回答:3

我正在制作检查表。
enter image description here

我的评估宏不适用于角度尺寸。我确定这是因为“°”字符。
当遇到带有该字符的单元格时,有没有办法截断或忽略“°”,以便循环的其余部分可以按预期运行?

这是评估代码的一部分。这涵盖“Shop Print Max”列中的非数字条目(在这些情况下,最大和最小列通常合并到一个单元格中)以及仅“Shop Print Max”列中的数字条目。

Sub Evaluate_Pre_Forge()
Dim R As Integer
Dim R2 As Integer
Dim Rng As Range
R = 12
R2 = 13
Do While (R < 70)

'(Text Entries in Column "N")
If (IsNumeric(Cells(R, 14))) = False Then
  For Each Rng In Range(("T" & R), ("W" & R2))
    If (Cells(R, 8) = "Y") = True Or (Cells(R, 8) = "y") = True Then
      If Not IsEmpty(Rng) Then
        If (IsNumeric(Rng)) = False And (Rng <> "Conforms") = True Then
          Rng.Interior.Color = 16777215
        ElseIf (IsNumeric(Rng)) = False And (Rng = "Conforms") = True Then
          Rng.Interior.Color = 7862528
        End If
      End If
    End If
  Next Rng
ElseIf (IsNumeric(Cells(R, 14))) = True Then
'(Numeric Value in Column "N" Only)
  If (Cells(R, 14).Value > 0) = True And (Cells(R, 17).Value <= 0) = True Then
    For Each Rng In Range(("T" & R), ("W" & R2))
      If (Cells(R, 8) = "Y") = True Or (Cells(R, 8) = "y") = True Then
        If Not IsEmpty(Rng) Then
          If (IsNumeric(Rng)) = True Then
            '(Max Value Greater Than 100)
            If Cells(R, 14).Value >= 100 Then
              If (Rng.Value >= 100) Then
                If Cells(R, 14).Value >= Rng.Value Then
                  Rng.Interior.Color = 7862528
                End If
              End If
              If (Rng.Value < 100) And (Rng.Value >= 10) Then
                Rng.Interior.Color = 7862528
              End If
              If (Rng.Value < 10) And (Rng.Value >= 0) Then
                Rng.Interior.Color = 7862528
              End If
            End If
            '(Max Value Between 10 and 100)
            If Cells(R, 14).Value < 100 And Cells(R, 14).Value >= 10 Then
              If (Rng.Value < 100) And (Rng.Value >= 10) Then
                If Cells(R, 14).Value >= Rng.Value Then
                  Rng.Interior.Color = 7862528
                End If
              End If
              If (Rng.Value < 10) And (Rng.Value >= 0) Then
                Rng.Interior.Color = 7862528
              End If
            End If
            '(Max Value Between 0 and 10)
            If Cells(R, 14).Value < 10 Then
              If (Rng.Value < 10) And (Rng.Value >= 0) Then
                If Cells(R, 14).Value >= Rng.Value Then
                  Rng.Interior.Color = 7862528
                End If
              End If
            End If
          ElseIf (IsNumeric(Rng)) = False And Rng = "Conforms" Then
            Rng.Interior.Color = 7862528
          End If
        End If
      End If
    Next Rng
  End If

End If
R = R + 2
R2 = R2 + 2
Loop

End Sub
excel vba special-characters
3个回答
1
投票

您可以简单地使用

val
功能。 这会返回字符串中包含的 numbers 作为适当类型的数值。

关于val函数

示例 VBA:

Dim MyValue
MyValue = Val("100.5°")    ' Returns 100.5

0
投票

Replace([YourReferenceHere], "°", "")
呢?这会将特殊字符替换为空字符串。


0
投票

您可以通过

if
声明轻松检查。请参阅下面的示例:

cv = Sheet1.Cells(1, 1)

If Right(Trim(cv), 1) = "°" Then
   cv = Left(Trim(cv), Len(cv) - 1)
End If
© www.soinside.com 2019 - 2024. All rights reserved.