Sub Myfind()Dim iRange As Range, i" />
乔山办公网我们一直在努力
您的位置:乔山办公网 > excel表格制作 > 求Excel VBA中<em>Find</em>及<em>Find</em&g

求Excel VBA中<em>Find</em>及<em>Find</em&g

作者:乔山办公网日期:

返回目录:excel表格制作


range.findnext(range.find(what))

Sub Myfind()
Dim iRange As Range, iFined As Range
Dim 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变量,如果7a64e4b893e5b19e331要查找包含istr变量的单元格,更改参数lookat:=xlPart
If iFined Is Nothing Then '判断 ifined变量是空
MsgBox "在" & iRange.Address(0, 0) & "区域里,没有找到内容等于" & iStr & "的单元格!"
Exit Sub
Else
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 If
MsgBox "在" & iRange.Address(0, 0) & "区域里,共找到内容等于" & iStr & "的单元格有:" & N & "个!"
End Sub
Columns和Ranges都可以7a64e78988e69d83365用findnext
Set findCell = Sheet1.Columns(coldw).Find(str2)
If Not findCell Is Nothing Then

firstAddress = findCell.Address

Do
dayInRow = findCell.Row
For i = 1 To day
mydate = DateSerial(year, month, i)
Sheet15.Cells(i + 1, 1) = mydate
j = 1
For lst = 0 To ListBox1.ListCount - 1
If ListBox1.Selected(lst) = True Then
str1 = ListBox1.List(lst)
Name1 = Left(str1, InStr(str1, "&") - 1)
col = Right(str1, Len(str1) - Len(Name1) - 1)
If CDate(Sheet1.Cells(dayInRow, col)) < mydate Then
Sheet15.Cells(i + 1, j + 1) = Sheet15.Cells(i + 1, j + 1) + 1
End If
j = j + 1
End If

Next
Next
set findCell = Sheet1.Columns(coldw).FindNext(findCell)
Loop While Not findCell Is Nothing And firstAddress <> findCell.Address
End If

Sub Myfind()
Dim iRange As Range, iFined As Range
Dim iStr, iAddress As String, N As Integer
'以上是定义使用到的变量e68a84e79fa5e98193365
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:=xlPart
If iFined Is Nothing Then '判断 ifined变量是空
MsgBox "在" & iRange.Address(0, 0) & "区域里,没有找到内容等于" & iStr & "的单元格!"
Exit Sub
Else
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 If
MsgBox "在" & iRange.Address(0, 0) & "区域里,共找到内容等于" & iStr & "的单元格有:" & N & "个!"
End Sub

相关阅读

关键词不能为空
极力推荐

ppt怎么做_excel表格制作_office365_word文档_365办公网