我有一个问题,如何使用find函数获取单元格地址.这是代码
Dim Found As Range
Set Found = Worksheets("Sheet 1").Cells.Find(What:="test", LookAt:=xlWhole, MatchCase:=True)
If Not Found Is Nothing Then
' do something
End If
Run Code Online (Sandbox Code Playgroud)
问题是当我尝试调试代码时,"Found"变量包含一个"字符串"而不是单元格地址.
不知道我的代码有什么问题.
看起来found.address
即使它显示为字符串,你也可以使用它.以下代码对我有用.
Sub findCellAddress()
Dim ra As Range
Set ra = Cells.Find(What:="fff", LookIn:=xlFormulas, LookAt _
:=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, MatchCase:= _
False, SearchFormat:=False)
If ra Is Nothing Then
MsgBox ("Not found")
Else
MsgBox (ra.Address)
End If
End Sub
Run Code Online (Sandbox Code Playgroud)
我在互联网上找不到这个。此代码将为您提供行和列。
Dim ThisPos As Range
With Range("A1:J100")
Set ThisPos = .Find(What:="List_Position", LookAt:=xlWhole, MatchCase:=False, SearchFormat:=False)
If Not ThisPos Is Nothing Then
Cell_Add = Split(ThisPos.Address, "$")
ThisCol = Cell_Add(1)
ThisRow = Cell_Add(2)
End If
End With
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
53947 次 |
最近记录: |