【问题标题】:How can I delete a entire row using a find function?如何使用查找功能删除整行?
【发布时间】:2017-08-29 06:41:47
【问题描述】:

我有一个包含公寓大楼数据的数据表。我制作了用户表单来添加、编辑和删除他们。但是,我删除它们的方式会在我的数据中留下一个空白,并且必须手动删除所有行以保持工作表看起来干净,这变得非常烦人。

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

或者是什么意思,如果你能按照我的思路来?

提前感谢您的帮助!!

【问题讨论】:

  • Delete a row in Excel VBA的可能重复
  • 我已经看过你建议的帖子,但由 Mrig 提供,FndRng.EntireRow.Delete 是我要找的。我知道我想要什么我只是很久没有使用 VBA 我有点迷茫。不过非常感谢!

标签: vba excel


【解决方案1】:

代替

fndRng.row.delete

使用

FndRng.EntireRow.Delete

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-09-17
    • 2011-08-23
    • 1970-01-01
    • 2021-10-10
    • 1970-01-01
    相关资源
    最近更新 更多