代码之家  ›  专栏  ›  技术社区  ›  Ahmad

哪个属性保存非连续单元格的结果范围中的项?

  •  1
  • Ahmad  · 技术社区  · 14 年前

    Find_Range 函数来自 OzGrid 它返回一个包含找到的项的范围对象。它成功地使用了它。我知道循环遍历结果范围的每一项允许对单个单元格进行更新/修改。Count属性显示正确的值。

    根本没有 Value Value2

    查找\u范围 (非连续单元格的范围)列出所有找到的项?

    编辑:

    更清楚一点-通常范围对象(如ffg)可以提供范围中所有选定项的变体数组

       Dim selRange as Range
       Dim vals as Variant 
       Set selRange = Range("A1:B10")
       vals = selRange.Value // 2D array with all values from the range
    

    然而,

       Set selRange = Range("A1,A2,B10") // this is similar to the result of the Find-Range Function
       vals = selRange.Value // will only provide the value of A1 and not all three
    

    Function Find_Range(Find_Item As Variant, _ 
        Search_Range As Range, _ 
        Optional LookIn As Variant, _ 
        Optional LookAt As Variant, _ 
        Optional MatchCase As Boolean) As Range 
    
        Dim c As Range 
        If IsMissing(LookIn) Then LookIn = xlValues 'xlFormulas
        If IsMissing(LookAt) Then LookAt = xlPart 'xlWhole
        If IsMissing(MatchCase) Then MatchCase = False 
    
        With Search_Range 
            Set c = .Find( _ 
            What:=Find_Item, _ 
            LookIn:=LookIn, _ 
            LookAt:=LookAt, _ 
            SearchOrder:=xlByRows, _ 
            SearchDirection:=xlNext, _ 
            MatchCase:=MatchCase, _ 
            SearchFormat:=False) 
            If Not c Is Nothing Then 
                Set Find_Range = c 
                firstAddress = c.Address 
                Do 
                    Set Find_Range = Union(Find_Range, c) 
                    Set c = .FindNext(c) 
                Loop While Not c Is Nothing And c.Address <> firstAddress 
            End If 
        End With 
    
    End Function
    
    1 回复  |  直到 13 年前
        1
  •  2
  •   jevakallio    14 年前

    Dim searchTerm As String
    searchTerm = "Search word"
    
    Dim results As Excel.Range
    Set results = Find_Range(Find_Item:=searchTerm, Search_Range:=ActiveSheet.Cells)
    
    If Not results Is Nothing Then
    
        Dim cell As Excel.Range
        For Each cell In results
            Debug.Print cell.Value
        Next cell
    
    End If
    

    For Each cell In results
    

    与相同

    For Each cell In results.Cells