如何使用find函数删除整行?

时间:2017-08-29 06:41:47

标签: excel vba excel-vba

我有一份数据表,其中包含公寓大楼的数据。我使用userforms添加租户,编辑和删除它们。然而,我删除它们的方式在我的数据中留下了一个空白,并且必须手动删除所有行以保持表格看起来干净,这变得非常烦人。

Sheet1.Select

Dim FndRng As Range

Set FndRng = Sheet1.Columns("C:C").Find(What:=cboName.Value,    LookIn:=xlFormulas, LookAt:=xlPart, _
            SearchOrder:=xlByRows, SearchDirection:=xlNext, MatchCase:=False, SearchFormat:=False)

If Not FndRng Is Nothing Then 'successful find
FndRng.Offset(0, -1).Value = ""
FndRng.Value = ""
FndRng.Offset(0, 1).Value = ""
FndRng.Offset(0, 2).Value = ""
FndRng.Offset(0, 3).Value = ""
FndRng.Offset(0, 4).Value = ""
FndRng.Offset(0, 5).Value = ""
FndRng.Offset(0, 6).Value = ""
FndRng.Offset(0, 7).Value = ""
FndRng.Offset(0, 8).Value = ""
FndRng.Offset(0, 9).Value = ""
FndRng.Offset(0, 10).Value = ""
FndRng.Offset(0, 11).Value = ""

cboName.Value = ""
txtCode.Value = ""
cboGrade.Value = ""
txtPhone.Value = ""
txtDormitory.Value = ""
cboPhase.Value = ""
cboCourse.Value = ""
cboStatus.Value = ""
txtGrad.Value = ""
txtCsd.Value = ""
txtSsn.Value = ""
txtComments.Value = ""
cboSex.Value = ""

Else ' unable to find the value in "Name"
MsgBox "Name not found in Datasheet, Do not change the name while editing the profile.", , "Name not Found"
End If

End Sub

但正如您所看到的那样,数据中只留下了很大的差距。 我想做像

这样的事情
fndRng.row.delete

或意味着什么,如果你可以按照我的思考过程?

提前感谢您的帮助!!

1 个答案:

答案 0 :(得分:2)

而不是

fndRng.row.delete

使用

FndRng.EntireRow.Delete