求Excel VBA中Find及Findnext的用法
的有关信息介绍如下:Sub Myfind()Dim iRange As Range, iFined As RangeDim iStr, iAddress As String, N As Integer'以上是定义使用到的变量Set iRange = Range("A2:A100") '给irange变量赋值为A2:A100区域iStr = Range("A1").Value '给要查找的字符串变量赋值为A1单元格的值Set iFined = iRange.Find(iStr, lookat:=xlWhole) '在irange区域内查找等于变量istr的单元格,并赋值给你ifined变量,如果要查找包含istr变量的单元格,更改参数lookat:=xlPartIf iFined Is Nothing Then '判断 ifined变量是空 MsgBox "在" & iRange.Address(0, 0) & "区域里,没有找到内庆喊容等于" & iStr & "的单元简差手格!" Exit SubElse iAddress = iFined.Address(0, 0) Do N = N + 1 Set iFined = iRange.FindNext(iFined) '继续向下查找等于istr变量的单元格 Loop While Not iFined Is Nothing And iAddress <> iFined.Address(0, 0) 'do循环的条件为ifined变拦嫌量非空,并且ifined变量的单元格地址不等于找到的第一个单元格地址End IfMsgBox "在" & iRange.Address(0, 0) & "区域里,共找到内容等于" & iStr & "的单元格有:" & N & "个!"End Sub