简体   繁体   English

Excel 2007 VBA:如果单元格值介于600和699之间,则删除行

[英]Excel 2007 VBA: delete row if cell value is between 600 and 699

I've been struggling with this question for a while. 我一直在努力解决这个问题。 I am trying to write the VBA code to finish this multi-worksheet macro and I'll say thank you in advance for your time & knowledge. 我正在尝试编写VBA代码来完成此多工作表宏,在此先感谢您的时间和知识。 I sincerely appreciate it. 我衷心感谢。

I have a sheet of roughly 10 columns, 4,000 rows. 我大约有10列,4,000行。 The goal is to search column "E" for values between 600 and 699, and delete any row that has column E with a value between 600 and 699. 目标是在“ E”列中搜索600到699之间的值,并删除所有E列在600到699之间的值的行。

Right now I'm using this line to delete a row containing "602": 现在,我正在使用此行删除包含“ 602”的行:

Dim FoundCell As Range
Set FoundCell = Worksheets("StoreEmployeeImport").Range("E:E").Find(what:=602)
Do Until FoundCell Is Nothing
    FoundCell.EntireRow.Delete
    Set FoundCell = Worksheets("StoreEmployeeImport").Range("E:E").FindNext
Loop

Is there a way to do this for all values between 600 and 650? 是否可以对600到650之间的所有值执行此操作? The 'quick and dirty way" is to write this loop for all fifty possible values between 600 and 650 BUT I know there is a better way. Probably much simpler. “快速而肮脏的方式”是为600至650 BUT之间的所有五十个可能值编写此循环,我知道这是一种更好的方式,可能简单得多。

THANKS! 谢谢!

This is how I handle it 这就是我的处理方式

'Get the last row, 65000th row and column E
finalRow=cells(65000,5).end(xlup).row
'Loop through data backwards
for i = finalRow to 1 step -1
  'Do your check
  if cells(i,5) > 600 and cells(i,5) < 650 then
    'Delete the row if criteria met
    cells(i,1).entirerow.delete
  end if
next i

Try this: 尝试这个:

Sub qwerty()
    Dim N As Long, i As Long
    N = Cells(Rows.Count, "E").End(xlUp).Row
    Application.ScreenUpdating = False
    For i = N To 1 Step -1
        v = Cells(i, "E").Value
        If v > 599 And v < 700 Then
            Cells(i, "E").EntireRow.Delete
        End If
    Next i
    Application.ScreenUpdating = True
End Sub

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM