Jumat, 19 Februari 2016

RE: [ExcelVBA] Code that needs help

 

Here is a way that is faster than looping if you have a large dataset

 

Dim rng As Range
Dim lastrow As Long

 

    Application.ScreenUpdating = False

   

    With ActiveSheet

   

        lastrow = .Cells(.Rows.Count, "C").End(xlUp).Row

        Set rng = .Range("C1").Resize(lastrow)

        rng.AutoFilter Field:=1, Criteria1:="=20", Operator:=xlOr, Criteria2:="=33"

        On Error Resume Next

        Set rng = rng.Offset(1).SpecialCells(xlCellTypeVisible)

        On Error GoTo 0

        If Not rng Is Nothing Then rng.EntireRow.Delete

        .Range("C1").AutoFilter

    End With

   

    Application.ScreenUpdating = True

End Sub

 

From: ExcelVBA@yahoogroups.com [mailto:ExcelVBA@yahoogroups.com]
Sent: 18 February 2016 04:59
To: ExcelVBA@yahoogroups.com
Subject: [ExcelVBA] Code that needs help

 

 

I have code that I want to modify if possible. The object of this code is to delete rows that contain a specific value in a specific column. Here is what I am using now:

Sub Delete_2033_Types()
'line below deletes rows that do not have a number value assigned in column 3
lrow = Cells(Rows.Count, 1).End(xlUp).Row
For i = lrow To 2 Step -1
If Not IsNumeric(Cells(i, 3)) Then Rows(i).Delete
Next i
End Sub
How can I modify this so that if the value in column 3 equals the integer 20 or 33 it will be deleted?

__._,_.___

Posted by: "Bob Phillips" <bob.phillips@dsl.pipex.com>
Reply via web post Reply to sender Reply to group Start a New Topic Messages in this topic (4)
----------------------------------
Be sure to check out TechTrax Ezine for many, free Excel VBA articles! Go here: http://www.mousetrax.com/techtrax to enter the ezine, then search the ARCHIVES for EXCEL VBA.

----------------------------------
Visit our ExcelVBA group home page for more info and support files:
http://groups.yahoo.com/group/ExcelVBA

----------------------------------
More free tutorials and resources available at:
http://www.mousetrax.com

----------------------------------

.

__,_._,___

Tidak ada komentar:

Poskan Komentar