在Excel中find单词
你知道当你点击control-F来查找单词,然后当你点击查找时,它会给你一个所有具有该单词的单元格的列表
我们怎样才能把它放在一个公式中,以便在表格中列出这些结果
A | B 1 apple
在工作表2中
A | B 1 apple cider 2 peas 3 cucumber 4 apple 5 apple rum 6 carrots 7 beans 8 carrots and apples
我想结果出来
A | B | C | D 1 apple apple cider apple rum carrots and apples
尝试在公式栏中input:
FIND(expression, text_value)
也要通过这个链接:
http://www.smartsheet.com/help-categories/formulas
在一个模块中写这个函数:
Public Function WordFinder(searchRange As Range, seekWord As String, iteration As Integer) Dim rangeCell As Range 'holder cell used in For-Each loop Dim rangeText As String 'holder for rangeCell's text Dim counter As Integer counter = 0 'loop through cells in the range For Each rangeCell In searchRange.Cells rangeText = rangeCell.Value 'capture the current cell value 'check if the seek word appears in the current cell If InStr(rangeText, seekWord) > 0 Then counter = counter + 1 'increment the occurrence counter If counter = iteration Then 'this is the occurrence we're looking for 'return it WordFinder = rangeText Exit Function End If End If Next rangeCell WordFinder = "n/a" 'that occurrence number was not found End Function
在结果表的最上面一行,在每个单元格中input此公式:
=wordfinder(Sheet2!$A1:$A8,"apple",column())
column()
随着每列逐渐增加,所以当你复制/粘贴到最上面一行时,它就会数起来。 美元符号确保参考文献完全保留在A列。
第二个参数(“苹果”)可以来自一个单元格,虽然我已经硬编码在这里。
有可能是一个更优雅的方式来做到这一点,但这是一个快速和肮脏的方式应该工作。
为了使用查找()
expression.Find(What, After, LookIn, LookAt, SearchOrder, SearchDirection, MatchCase, MatchByte, SearchFormat)
例:
Cells.Find(What:="Cat", After:=ActiveCell, LookIn:=xlValues, LookAt:= xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, MatchCase:=False, SearchFormat:=False)
我不得不手动查找值。