+ Reply to Thread
Results 1 to 2 of 2

VBA to delete row if value in cell is larger or smaller than a specified value

Hybrid View

judasdac VBA to delete row if value in... 03-03-2009, 01:49 PM
VBA Noob Re: VBA to delete row if... 03-03-2009, 02:54 PM
  1. #1
    Registered User
    Join Date
    11-14-2008
    Location
    Brooklyn, NY, USA
    Posts
    53

    VBA to delete row if value in cell is larger or smaller than a specified value

    Hi All,

    I'd like to delete the rows in column K if the value is between -10,000 or +10,000. I found some code from en earlier post that I've been trying to work with, but can't seem to quite get it.

    Here is the code:
    Dim Rng As Range
    Dim calcmode As Long
        
        With Application
             calcmode = .Calculation
            .Calculation = xlCalculationManual
            .ScreenUpdating = False
        End With
      
        With ActiveSheet
            .AutoFilterMode = False
            
            .Range("K2:k729" & .Rows.Count).AutoFilter Field:=1, Criteria1:=">=(10000)", Criteria2:="<=10000"
            With .AutoFilter.Range
                On Error Resume Next
                Set Rng = .Offset(1, 0).Resize(.Rows.Count - 1, 1) _
                          .SpecialCells(xlCellTypeVisible)
                On Error GoTo 0
                If Not Rng Is Nothing Then Rng.EntireRow.Delete
            End With
          
            .AutoFilterMode = False
        End With
        With Application
            .ScreenUpdating = True
            .Calculation = calcmode
        End With
    Thanks in advance for the help.

    Cheers

  2. #2
    Forum Contributor VBA Noob's Avatar
    Join Date
    04-25-2006
    Location
    London, England
    MS-Off Ver
    xl03 & xl 07(Jan 09)
    Posts
    11,988

    Re: VBA to delete row if value in cell is larger or smaller than a specified value

    Try the below. It assumes Header in K1

    Dim Rng As Range
    Dim calcmode As Long
        
        With Application
             calcmode = .Calculation
            .Calculation = xlCalculationManual
            .ScreenUpdating = False
        End With
      
        With ActiveSheet
            .AutoFilterMode = False
            
            .Range("K1:K" & .Rows.Count).AutoFilter Field:=1, Criteria1:=">=-10000", Criteria2:="<=10000"
            With .AutoFilter.Range
                On Error Resume Next
                Set Rng = .Offset(1, 0).Resize(.Rows.Count - 1, 1) _
                          .SpecialCells(xlCellTypeVisible)
                On Error GoTo 0
                If Not Rng Is Nothing Then Rng.EntireRow.Delete
            End With
          
            .AutoFilterMode = False
        End With
        With Application
            .ScreenUpdating = True
            .Calculation = calcmode
        End With
    VBA Noob
    _________________________________________


    Credo Elvem ipsum etian vivere
    _________________________________________
    A message for cross posters

    Please remember to wrap code.

    Forum Rules

    Please add to your signature if you found this link helpful. Excel links !!!

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1