Set findValue = ActiveSheet.usedrange.FindNext(After:=findValue) ‘使用findnext继续往下查找,After参数是指定从哪个单元格的下一个开始查找,其中“:=”后面的findvalue是上一次查找到的位置对象变量,意思就是从这一个单元格的下一个单元格 If findValue.Address = a Then '如果当前的位置和最开始找到的位置一...
expression.Find(What, After, LookIn, LookAt, SearchOrder, SearchDirection, MatchCase, MatchByte, SerchFormat) expression 必需。该表达式返回一个 Range 对象。 What Variant 类型,必需。要搜索的数据。可为字符串或任意 Microsoft Excel 数据类型。 After Variant 类型,可选。表示搜索过程将从其之后开始进行的...
Private Sub CommandButton1_Click()Dim x As String, xArr, n As IntegerReDim xArr(0)x = ActiveSheet.OLEObjects("TextBox1").Object.Valuex = VBA.Trim(x)Dim FirstAddr As StringIf getRanges Is Nothing Then MsgBox "没有选择查找范围!", vbInformation, "错误提示": Exit SubDim R As RangeWit...
Dim rng As Range Set rng =Range("A1:D3").Find(What:="1", SearchOrder:=xlByColumns) MsgBox "查找到内容为1的单元格为: "& rng.Address(RowAbsolute:=False, ColumnAbsolute:=False) End Sub 运行代码后,将返回单元格B3。...
同样,在ExcelVBA中使用与该功能对应的Find方法,提供了一种在单元格区域查找特定数据的简单方式,并且比用传统的循环方法进行查找的速度更快。 02 Find函数的格式是什么样子的? Find函数的语法格式如下: Range.Find(What,[After],[LookIn],[LookAt],[SearchOrder],[SearchDirection],[MatchCase],[MatchByte],[...
c.Value = 5 Set c = .FindNext(c) Loop While Not c Is Nothing And c.Address <> firstAddress End If End With 经修改后的示例代码如下,即在原代码中加了一句错误处理语句On Error Resume Next,忽略所发生的错误。 Sub test1() Dim c As Range, firstAddress As String ...
2. 在Excel中有一个查找的功能,可以定位姓名在源数据中的位置。 3. 在VBA中同样可以利用此功能,对应的就是Find方法。 在Excel文件,点击“开发工具”,打开Visual Basic,添加模块和过程,称之为“查找数据”。 4. 在此例中,我们通过学生姓名(H2单元格)作为条件,将查找的结果(学生的英语成绩)返回到I2单元格,针...
VB With Worksheets(1).Range("a1:a500") Set c = .Find(2, lookin:=xlValues) If Not c Is Nothing Then firstAddress = c.Address Do c.Value = 5 Set c = .FindNext(c) Loop While Not c Is Nothing End If End With
6.如果start_num大于within_text的长度,则FIND和FINDB返回错误值#VALUE!. 7.也可使用SEARCH查找其他文本字符串中的某个文本字符串,但是,FIND和SEARCH不同,FIND区分大小写并且不允许使用通配符. 下面我们通过一个实例来看看这个函数的妙用:如上的截图:问题一如何把A:B 以冒号为分隔符来进行拆分呢?问题二:...
Sub FindString() Dim c As Range Dim firstAddress As String With Worksheets(1).Range("A1:A500") Set c = .Find("abc", LookIn:=xlValues) If Not c Is Nothing Then firstAddress = c.Address Do c.Value = Replace(c.Value, "abc", "xyz") Set c = .FindNext(c) Loop While Not c Is...