哪个属性保存在非连续单元格范围内的项目?

我使用了Find_Range函数,它返回一个Range对象和find的项目。 它成功地使用了它。 我知道循环遍历结果Range的每个项目允许更新/修改单个单元格。 Count属性显示正确的值。

没有Value属性, Value2属性只显示find的第一个项目。

我的问题是 – Find_Range (它是一系列非连续单元格)的结果中的属性列出了所有find的项目?

编辑:

更清晰一点 – 通常一个Range对象,如ffg,可以提供Range中所有选定项目的Variant数组

  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 

不是100%确定你的意思,但列举的结果似乎工作:

 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循环中的结果时,它会隐式地调用Range对象的.Cells属性,所以

 For Each cell In results 

是相同的

 For Each cell In results.Cells 

因为Find_Range返回多个单元格的范围,所以没有可以将结果作为列表的单个属性。 你必须循环遍历范围并自己构build列表。