且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

删除不等于组合框值的行?

更新时间:2023-02-08 22:09:29

要删除行,请使用 EntireRow :

wkss.Rows(i).EntireRow.Delete 应该可以做到!

(对于价值而言,删除整个列也一样,请使用 EntireColumn.Delete )

(For what it's worth, the same goes for removing an entire column, use EntireColumn.Delete)

让我们通过将亲子关系分配给并使用 With 语句来清除范围和选择

Let's clear up the ranges and selections by assigning parentage with a With statement.

Dim wkss As Worksheet, wkJob As Worksheet
Dim i As Long
Set wkss = Sheets("TempWs6")
Set wsJob = Sheets("Job")

With wkss

For i = .Cells(.Rows.Count, 10).End(xlUp).Row To 1 Step -1
    If .Cells(i, 10) <> wsJob.ComboBox1.Value Then
        .Rows(i).EntireRow.Delete
    End If
Next i
End With

.Cells([...]).行至1步骤-1 执行此操作:从最后一行开始(从 ...(xlUp)获得).行),运行下面的代码,然后步进"上一行,然后再次运行,并重复直到到达行 1 .

The .Cells([...]).Row to 1 Step -1 does this: Starting at your last row (which you get from ...(xlUp).Row), run the code below, then "step" up one row, and run again, and repeat until you reach row 1.