公式留下空白

时间:2018-02-12 16:49:36

标签: excel vba excel-vba excel-formula

我有以下公式用于标记ListObject中的行:

=IF( [@[Is Closed]]="Y", "", "Y")

我有一些通过StrCmp查找这些值的vba代码,并且惊讶地发现单元格的Text属性是" Y" (而不是" Y")。

有一些明显的简单工作,但是有人可以解释为什么公式会留下空白以及如何强迫它不去?

干杯,

更新

'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
' FindAllInColumn
' To find a value regardless of hidden rows and autofulter settings that can make
' other methods unreliable
'
' aSearchRange  :  the range of data to search, which MUST be a single column
' aLookUpVal    :  the value
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
Function FindAllInColumn(aSearchRange As Range, aLookUpVal As Variant) As Excel.Range
    Debug.Assert aSearchRange.Columns.Count = 1

    Dim rngEach As Range
    Dim rngResult As Excel.Range

    For Each rngEach In aSearchRange
'        Debug.Print rngEach.Address & ": Value " & rngEach.Text
'        If IsValued(rngEach.Text) Then Stop

        If (StrComp(rngEach.Text, aLookUpVal) = 0) Then
            If rngResult Is Nothing Then
                Set rngResult = rngEach
            Else
                Set rngResult = Application.Union(rngResult, rngEach)
            End If
        End If
    Next rngEach

    Set FindAllInColumn = rngResult
End Function

FIX

StrComp(rngEach.Value2, aLookUpVal, vbTextCompare)

将.Text更改为.Value2。奇怪,但至少它现在有效

1 个答案:

答案 0 :(得分:1)

通常,Excel中的空格有时会导致很多问题。 OP已经发现自己,.question { font: bold 24px Arial, sans-serif; } 似乎是许多奇怪案例的普遍问题解决者。

尝试选择单元格并检查以下代码,它将打印可能的“隐藏”空格:

.Value2