Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
706 views
in Technique[技术] by (71.8m points)

excel - How to delete every row in a range that contains data?

In a big data set I am trying to find each cell in column J that contains any data so "is not blank", then delete that row that contains data. My code however won't work for it:

Dim rng3 As Range

Do
    Set rng3 = Columns("J:J")
    If Not rng3 Is Nothing Then
        rng.EntireRow.Delete
    Else
        Exit Do
    End If
Loop

I was hoping somebody can help me with this.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)
  1. Select a range you need
  2. Press F5
  3. Press Special... button
  4. Select Constants or Formulas (with other selections, if needed)
  5. Press OK
  6. Now go to: Home -> Cells -> Delete (arrow) -> Delete Sheet Rows

UPDATE

Macros:

Sub DeleteRowsWithData()

    Dim rng As Range

    ' Change to the range you need
    Set rng = Range("A1").CurrentRegion

    ' Change field to the one you need
    rng.AutoFilter Field:=1, Criteria1:="<>", Operator:=xlFilterValues

    With rng
        With .Offset(1).Resize(.Rows.Count - 1) 'Exclude header
            Application.DisplayAlerts = False
            .Rows.Delete
            Application.DisplayAlerts = True
        End With
    End With

End Sub

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...