在用户窗体中查找键值的行和列
我有一个用户表单用户键入他们的ID号码到一个表。 但我怎么能捕获表中的行和列的ID号,并删除它们。
Set f = Worksheets("data").Range("4:4").Find(What:=TextBox2.Value) If Worksheets("data").Cells(f.Row, f.Column).Value = TextBox2.Value Then Worksheets("data").TextBox2.Value.Delete End If
非常感谢你
Find()
返回Find()
的单元格:如果没有匹配,则返回Nothing
。
只要Find()
find一个匹配,那么你可以直接使用它:不需要提取f.Row
和f.Column
,然后把它们变回相同的Range。 即f
和Worksheets("data").Cells(f.Row, f.Column)
引用同一个对象。
Set f = Worksheets("data").Range("4:4").Find(What:=TextBox2.Value, lookat:=xlWhole) If Not f Is Nothing Then f.Delete End If