获取包含某个文本的单元格的引用 [英] Get the reference of a cell containing a certain text

查看:419
本文介绍了获取包含某个文本的单元格的引用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的工作表中有一个包含特定文本的单元格(例如hello),我想知道它是哪个单元格。我想知道这个单元格的引用(例如B52)。



我用INDEX或MATCH公式尝试了一些东西,但是我很困惑我应该做这种查询。



如果有人可以提供一些提示,那将是很棒的。



谢谢提前!

解决方案

尝试这个小宏:

  Sub WhereIs()
Dim r As Range
对于每个r在ActiveSheet.UsedRange
如果InStr(1,r.Text,hello)> 0然后
MsgBox r.Address
退出子
结束如果
下一步r
结束子

编辑#1



用户定义函数中的相同方法 (UDF)格式:

 公共函数WhereIs(rIn As Range,sIn As String)As String 
WhereIs =
Dim r As Range
对于每个r在rIn
中如果InStr(1,r.Text,sIn)> 0然后
WhereIs = r.Address(0,0)
退出函数
结束如果
下一步r
结束函数

这里是在工作表中使用的示例:





编辑#2 p>

可以在没有 VBA 的情况下查找二维的值
说我们有如下数据:





strong> K1 输入:
hello

K2 中输入数组公式


$ b $ ($ A $ 1:$ H $ 14 = K1,COLUMN($ A $ 1:$ H $ 14)-COLUMN($ A $ 1)+1))

K3 中输入数组公式

K4 输入: p>

  = ADDRESS(K3,K2)

K2 给出列, K3 给出行, K4 给出单元格的地址($ E $ 11)



Ctrl + Shift + 输入而不是仅输入输入 kbd>键。


I have somewhere in my worksheet a cell containing a specific text (for exemple "hello") and I want to know which cell is it. I want to know the reference of this cell (for exemple "B52").

I tried some things with the INDEX or MATCH formula but I'm quite confused about how should I do for this kind of query.

It would be great if someone could give some tips.

Thank's in advance !

解决方案

Try this small macro:

Sub WhereIs()
    Dim r As Range
    For Each r In ActiveSheet.UsedRange
    If InStr(1, r.Text, "hello") > 0 Then
        MsgBox r.Address
        Exit Sub
    End If
    Next r
End Sub

EDIT#1

Here is the same approach in User Defined Function (UDF) format:

Public Function WhereIs(rIn As Range, sIn As String) As String
    WhereIs = ""
    Dim r As Range
    For Each r In rIn
        If InStr(1, r.Text, sIn) > 0 Then
            WhereIs = r.Address(0, 0)
            Exit Function
        End If
    Next r
End Function

and here is an example of its use in the worksheet:

EDIT#2

It is possible to lookup a value in two dimensions without VBA
say we have data like:

In K1 enter:
hello

In K2 enter the array formula

=MIN(IF($A$1:$H$14=K1,COLUMN($A$1:$H$14)-COLUMN($A$1)+1))

In K3 enter the array formula

=MIN(IF($A$1:$H$14=K1,ROW($A$1:$H$14)-ROW($A$1)+1))

In K4 enter:

=ADDRESS(K3,K2)

K2 gives the column, K3 gives the row, and K4 gives the address of the cell ($E$11)

Array formulas must be entered with Ctrl + Shift + Enter rather than just the Enter key.

这篇关于获取包含某个文本的单元格的引用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆