在包含特定文本的所有单元格中find具有特定文本,多次出现和过去活动单元格的单元格

我目前正在编写一份源自Infoview(SAP业务对象)的报告,

这是一个每周提供有价值信息的报告,以提高对当前店铺绩效的认识。

像post的瓦片可能表明我想find具有特定文本的单元格。 它有多个事件,我想要在所有这些实例中通过先前select的单元格。

我可以通过Ctrl-F,“全部search”(对于“特定文本”)和粘贴(之前select的单元格)来达到相同的结果( http://www.extendoffice.com/documents/excel/816-excel -select-cells-with-specific-text.html )但是我想自动化这个。

我想用:

Cells.Find(What:="[ö]", After:=ActiveCell, LookIn:=xlFormulas, LookAt:= _ xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, MatchCase:=False _ , SearchFormat:=False).Activate 

  Cells.FindNext(After:=ActiveCell).Activate 

但是我不能把这两个macros合并成一个macros,它给了我上面描述的结果。

之前选定的单元格包含一个公式,其中包含索引(匹配)以及对与“特定文本”相同行上的单元格的引用。 在我看来,这样做的东西节省了我dynamic单元格引用等很多麻烦。

我希望你能帮上忙

你的要求有点含糊,但我相信这会让你开始

 Dim PasteValue as string 'this is what you're pasting in Dim WS as Worksheet Dim FirstCell as string Dim rng as range PasteValue = 'do something here to get your value set rng = Cells.Find(What:="[ö]", LookIn:=xlFormulas, LookAt:= xlPart, _ SearchOrder:=xlByRows, SearchDirection:=xlNext, MatchCase:=False, _ SearchFormat:=False) while not rng is nothing 'make sure you found something if len(FirstCell) = 0 then firstcell = rng.address 'save this spot off so we don't keep looping end if rng.value = PasteValue 'now find the next one set rng = Cells.Find(What:="[ö]", LookIn:=xlFormulas, LookAt:= xlPart, _ SearchOrder:=xlByRows, SearchDirection:=xlNext, MatchCase:=False, _ SearchFormat:=False) if rng.address = FirstCell then 'back at the first cell set rng = nothing 'so get out of the loop endif end while 

感谢上面的代码,它帮助了很多。

这是最后的代码,以防万一需要它。 该

 If rng Is Nothing Then Exit Do Loop While rng.Address <> strFirstAddress 

是特别有用的。

 Sub Fill_VCNC() Dim formula_ö As String Dim rng As Range Dim strFirstAddress As String With Range("S:S") Set rng = Cells.Find(What:="[ö]", LookIn:=xlValues, LookAt:=xlPart, _ SearchOrder:=xlByRows, SearchDirection:=xlNext, MatchCase:=False, _ SearchFormat:=False) If Not rng Is Nothing Then strFirstAddress = rng.Address Do rng.formula = formula_ö .NumberFormat = "0.00" Set rng = .FindNext(rng) If rng Is Nothing Then Exit Do Loop While rng.Address <> strFirstAddress End If End With End Sub 

(来源: https : //social.msdn.microsoft.com/Forums/en-US/958fca4e-b19d-4b50-8235-e05adc7f25d5/loop-through-a-range-until-value-not-found?forum =exceldev )