删除不等于组合框值的行? [英] Delete rows not equal to combobox value?

查看:31
本文介绍了删除不等于组合框值的行?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试删除不等于所选组合框值的行.我有以下代码,但出现运行时错误424对象.有人可以协助吗?

I am trying to delete rows that are not equal to a combobox value that is selected. I have the following code, but i get a run-time error 424 Object required. Can anyone assist?

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

wkss.Select

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

非常感谢!

推荐答案

要删除行,请使用 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.

这篇关于删除不等于组合框值的行?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆