查找具有特定文本、多次出现的单元格,并将活动单元格粘贴到包含特定文本的所有单元格中
find a cell with specific text, multiple occurences, and past active cell in all cells containing specific text
我目前正在处理一份来自 Infoview(SAP 业务对象)的报告
这是一份每周提供有价值信息的报告,以提高对当前商店绩效的认识。
就像 post 的磁贴一样,可能会显示我想查找包含特定文本的单元格。它有多次出现,我想在所有这些情况下都过去一个以前选择的单元格。
我可以通过 Ctrl-F、"Search all"(对于 "specific text")和粘贴(之前选择的单元格)达到相同的结果
(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
但我无法将这两者合并为一个宏来给出我上面描述的结果。
先前选择的单元格包含一个公式,其中包含索引(匹配项)和对与 "specific text" 位于同一行的单元格的引用。
在我看来,这种做事的方式为我省去了动态单元格引用等方面的很多麻烦。
希望能帮到你
您的要求有点含糊,但我相信这会让您入门
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
我目前正在处理一份来自 Infoview(SAP 业务对象)的报告
这是一份每周提供有价值信息的报告,以提高对当前商店绩效的认识。
就像 post 的磁贴一样,可能会显示我想查找包含特定文本的单元格。它有多次出现,我想在所有这些情况下都过去一个以前选择的单元格。
我可以通过 Ctrl-F、"Search all"(对于 "specific text")和粘贴(之前选择的单元格)达到相同的结果 (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
但我无法将这两者合并为一个宏来给出我上面描述的结果。
先前选择的单元格包含一个公式,其中包含索引(匹配项)和对与 "specific text" 位于同一行的单元格的引用。 在我看来,这种做事的方式为我省去了动态单元格引用等方面的很多麻烦。
希望能帮到你
您的要求有点含糊,但我相信这会让您入门
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