请问我要写一段excel下的vba,功能是查找包含某一字段的单元格,并返回其行数,应该怎么写呢?

2024-11-05 11:49:14
推荐回答(3个)
回答1:

.find (what:="许嵩",lookat:=xlpart)
好象是这样吧
给一个在用的具体例子吧!
Dim F As Boolean
Set Rng = .Rows("1:1").Find(what:="责任部门", lookat:=xlWhole) '将上面没在有全部再出来一次

If Not Rng Is Nothing Then
k = Rng.Column
Lrow = .Cells(65536, k).End(xlUp).Row
ReDim arr2(1 To Lrow - 1) ' '余下的没有机台的责任部门
jj = 1
For i = 2 To Lrow
F = False
A = .Cells(i, k)
For j = 1 To UBound(arr)
If Len(arr(j, 1)) > 0 Then If arr(j, 1) = A Then F = True: Exit For
Next
If Not F Then arr2(jj) = A: jj = jj + 1
Next
Else
MsgBox "基础资料表中没有责任部门"
End If

回答2:

讲明白点,这样我都听不懂

回答3:

如果有不止一个单元格包含你要找的某字段,返回哪一个的行数?