[英]Excel Finding a string
I want to know how to use the find command to search for the string of the current active cell. 我想知道如何使用find命令来搜索当前活动单元格的字符串。 I though this would work, but I keep getting the "Invalid Qualifier" Error 我虽然可以,但是我一直收到“无效的限定词”错误
Dim yaxis As String
Dim yaxis2 As Range
Yaxis = ActiveCell.Value
Yaxis2 = ActiveSheet.Cells.Find(What:=Yaxis.Value)
Error locates me to this part (What:= Yaxis .Value ) 错误将我定位到这部分(内容:= Yaxis .Value )
How can I use the find command to find the string yaxis Is equal to? 如何使用find命令查找字符串yaxis等于?
The problem is in your use of Yaxis.Value
. 问题出在您使用Yaxis.Value
。 Yaxis
is a string variable and doesn't have a Value
property. Yaxis
是一个字符串变量,没有Value
属性。 Instead, just use Yaxis
. 相反,只需使用Yaxis
。 You will also need to use the Set
keyword when assigning to an object variable. 分配给对象变量时,还需要使用Set
关键字。 Here's the code: 这是代码:
Dim Yaxis As String
Dim Yaxis2 As Range
Yaxis = Workbooks("book_name.xlsx").Worksheets("sheet_name").Selection.Value
Set Yaxis2 = Workbooks("book_name.xlsx").Worksheets("other_sheet_name").Cells.Find(What:=Yaxis)
If you need to search for the value of the active cell on a different sheet, you must specify the sheet you want to search. 如果需要搜索另一张图纸上的活动单元格的值,则必须指定要搜索的图纸。 There can only be one ActiveCell
and it will be on the ActiveSheet
. 只能有一个ActiveCell
,它将位于ActiveSheet
。
For example, if Sheet1
is active and you want to search for the active cell's value on Sheet2
, use: 例如,如果Sheet1
是活动的,并且您要在Sheet2
上搜索活动单元格的值,请使用:
Dim r As Range
Set r = Sheet2.Cells.Find(ActiveCell.Value)
If Not r Is Nothing Then
Debug.Print "Found active cell's value on Sheet2 at: " & r.Address
End If
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.