我在Excel插件中有一个VB.Net函数,我需要在工作表中找到第一个字符串,然后返回单元格的整个值。例如,如果单元格F4包含"苹果和橙子",则Findit(" apples")应该找到$ F $ 4的范围,并返回"苹果和橙子" ;
在下面的代码中,我在MatchedRange中存储了正确的范围,但我无法弄清楚如何使用它来获取该单元格的值。我知道我需要让细胞活跃起来,但这就是我挣扎的地方。
Private Sub FixFormulasButton_OnClick(sender As Object, control As IRibbonControl, pressed As Boolean) Handles FixFormulasButton.OnClick
Dim ws As Object = CType(ExcelApp.ActiveSheet, Excel.Worksheet)
Dim cells As Object = ws.Cells
Dim MatchRange As Object = CType(cells.Find("apples", LookAt:=Excel.XlLookAt.xlPart, Lookin:=Excel.XlFindLookIn.xlFormulas), Excel.Range)
If MatchRange Is Nothing Then
MessageBox.Show("found no apples", "do nothing", MessageBoxButtons.OK)
Else
MessageBox.Show(the contents of the cell at the range found above)
End if
End Sub