Excel VBA按找到的单元格值删除行
我有这段代码,我想按单元格值删除所有包含“BSB*”的行(因此有BSB 1、2等值)。这段代码部分工作。它仅每秒删除包含BSB的单元格。所以我有BSB2,4等等。我想删除所有BSB值出现在特定列ofc中的行。 p、 s英语是我的第二语言,如果我需要澄清什么,请让我知道Excel VBA按找到的单元格值删除行,excel,vba,Excel,Vba,我有这段代码,我想按单元格值删除所有包含“BSB*”的行(因此有BSB 1、2等值)。这段代码部分工作。它仅每秒删除包含BSB的单元格。所以我有BSB2,4等等。我想删除所有BSB值出现在特定列ofc中的行。 p、 s英语是我的第二语言,如果我需要澄清什么,请让我知道 Option Explicit Sub PrList() Dim wb As Workbook Dim ws As Worksheet Dim r As Range Dim i As Range Set wb = W
Option Explicit
Sub PrList()
Dim wb As Workbook
Dim ws As Worksheet
Dim r As Range
Dim i As Range
Set wb = Workbooks.Open("?????")
Set ws = wb.Worksheets("owssvr")
With ws.Range("A1").CurrentRegion
.Find(What:="Product_Number", LookAt:=xlWhole).Name = "Product_Number"
.Find(What:="Product_Status", LookAt:=xlWhole).Name = "Product_Status"
.Find(What:="Group_of_product", LookAt:=xlWhole).Name = "Group_of_product"
End With
Set i = ws.Range("Product_Number", Range("Product_Number").End(xlDown))
For Each r In i
If r Like "BSB*" Then
r.Rows.Delete
End If
Next r
End Sub
试试这个
Option Explicit
Sub NAPP_PrList()
Dim wb As Workbook
Dim ws As Worksheet
Dim r As Range
Dim i As Range
Dim j as Long
Set wb = Workbooks.Open("?????")
Set ws = wb.Worksheets("owssvr")
With ws.Range("A1").CurrentRegion
.Find(What:="Product_Number", LookAt:=xlWhole).Name = "Product_Number"
.Find(What:="Product_Status", LookAt:=xlWhole).Name = "Product_Status"
.Find(What:="Group_of_product", LookAt:=xlWhole).Name = "Group_of_product"
End With
Set i = ws.Range("Product_Number", Range("Product_Number").End(xlDown))
For j = i.Rows.Count To 1 Step -1
If i(j, 1) Like "BSB*" Then i(j, 1).EntireRow.Delete
Next
End Sub
试试这个
Option Explicit
Sub NAPP_PrList()
Dim wb As Workbook
Dim ws As Worksheet
Dim r As Range
Dim i As Range
Dim j as Long
Set wb = Workbooks.Open("?????")
Set ws = wb.Worksheets("owssvr")
With ws.Range("A1").CurrentRegion
.Find(What:="Product_Number", LookAt:=xlWhole).Name = "Product_Number"
.Find(What:="Product_Status", LookAt:=xlWhole).Name = "Product_Status"
.Find(What:="Group_of_product", LookAt:=xlWhole).Name = "Group_of_product"
End With
Set i = ws.Range("Product_Number", Range("Product_Number").End(xlDown))
For j = i.Rows.Count To 1 Step -1
If i(j, 1) Like "BSB*" Then i(j, 1).EntireRow.Delete
Next
End Sub
尝试运行
For
循环backwards@Gary您是指End(xlup))
而不是xl down
?否………从列的底部开始,向上…………查看brainiac的答案。尝试运行For
循环backwards@Gary你的意思是“学生”End(xlup))
而不是xl down
?否………从列的底部开始,向上………参见brainiac的答案。