根据一系列条件(复数)删除行

时间:2019-03-26 16:57:15

标签: excel vba range

自从我使用VBA已经有一段时间了。我有一系列要搜索表的唯一值。如果这些值存在于上述表格中,请删除整行。

我能够遍历并删除特定的奇异值,但难以解决多个问题。我试图用Range()和一个数组替换“ 30ExGEPAc30Q4”(下面的代码),但不能完全理解。这是到目前为止我得到的:

Sub test()

Dim x As Long
Dim lastrow As Long

lastrow = Sheets("LRP").ListObjects("Data_LRP").Range.Rows.Count

Worksheets("LRP").Activate
    For x = lastrow To 1 Step -1
        If Cells(x, 1).Value = "30ExGEPAc30Q4" Then
            Rows(x).Delete
        End If
    Next x
End Sub

2 个答案:

答案 0 :(得分:0)

如果我对您的理解正确,这就是您要实现的目标;我已经清理了一些不必要的位,现在您只需要根据需要编辑x和lastrow。

Sub test()

Dim x As Long
Dim lastrow As Long

'lastrow = Sheets("LRP").ListObjects("Data_LRP").Range.Rows.Count
x = 1
lastrow = 21


'Worksheets("LRP").Activate
Do While x <= lastrow
'    For x = lastrow To 1 Step -1
        If Cells(x, 1).Value = "30ExGEPAc30Q4" Then
            Rows(x).Delete
            lastrow = lastrow - 1
        Else
            x = x + 1
        End If
'    Next x

Loop
End Sub

答案 1 :(得分:0)

对于那些好奇的人,最终看起来像这样。感谢您的所有帮助!

import requests
from bs4 import BeautifulSoup

baseUrl = 'https://www.etsy.com/shop/JpKrHk/sold?ref=pagination&page=2'

res = requests.get(baseUrl)
soup = BeautifulSoup(res.text,'lxml')
items = [item.get_text(strip=True) for item in soup.select(".v2-listing-card__info h2")]
items = {i:items.count(i) for i in items}
print(items)
>>> {'1612-Plain 08, 3 sheets Korean Cotton Sticker sheet Suatelier  Kawaii sticker, Cute stickers, Scrapbooking materialPlanner': 1, '1610-Plain 06, 3 sheets Korean Cotton Sticker sheet Suatelier  Kawaii sticker, Cute stickers, Scrapbooking materialPlanner': 1, '1605-Plain 01, 6mm Korean Sticker sheet Suatelier  Kawaii sticker, Cute stickers, Scrapbooking material 3 sheetsPlanner': 1, 'best offer 1 Pen with 5 refills pcs Japan [Muji] MomA 0.38mm/0.5mm Gel INK PEN Black/Blue COLOUR': 1, '1061- daily Korean Travel Sticker sheet Suatelier  Kawaii sticker, Cute stickers, Scrapbooking materialPlanner': 1, '2018 new collection 60 style can choose One of the Limited Japan Kinds Pilot Frixion Stamp SPF-12 erasable scrapbook': 14, 'Zebra Justfit Mojini Line Highlighter - 5 Color Set WKS22-5C': 1, "Let's Color 6 colors fast dry Ink Pads for Fingerprints, Brilliance Drop Ink Pad, Fingerprint Ink Pad, Thumbprint Guest Book": 1, '2019 new collection One of 98-115 the Limited Japan Kinds Pilot Frixion Stamp SPF-12 erasable': 1, '1082 - daily in Tokyo Korean sheet Suatelier  Kawaii sticker, Cute stickers, Scrapbooking materialPlanner': 1, '2018 new collection 72 style can choose One of 61-72 the Limited Japan Kinds Pilot Frixion Stamp SPF-12 erasable scrapbook': 1}