+ Reply to Thread
Results 1 to 2 of 2

How to delete rows of data based on cell values in VB?

Hybrid View

drx How to delete rows of data... 10-24-2011, 04:23 PM
Paul Re: How to delete rows of... 10-24-2011, 04:45 PM
  1. #1
    Registered User
    Join Date
    10-17-2011
    Location
    England
    MS-Off Ver
    Excel 2010
    Posts
    3

    How to delete rows of data based on cell values in VB?

    Hi all,
    I have a block of data in columns AH to AM.

    What I want to do is delete any rows which contain a "0" as the cell value in column AK, with VBA.

    Note I don't want to delete the entire row, just the selection across AH to AM (similar to "shift cells up" type manual operation).

    Any ideas?

  2. #2
    Forum Expert Paul's Avatar
    Join Date
    02-05-2007
    Location
    Wisconsin
    MS-Off Ver
    2016/365
    Posts
    6,887

    Re: How to delete rows of data based on cell values in VB?

    Hi Drx,

    The following macro will delete columns AH:AM for any row where AK has the value 0. (e.g. Deletes AH3:AM3, shifting the cells below that up a row)

    Hope it helps!
    Sub delrows()
    Dim i As Long, LR As Long
    Application.ScreenUpdating = False
    LR = Range("AK" & Rows.Count).End(xlUp).Row
    For i = LR To 1 Step -1
        If Cells(i, "AK").Value = 0 Then
            Range(Cells(i, "AH"), Cells(i, "AM")).Cells.Delete Shift:=xlShiftUp
        End If
    Next i
    Application.ScreenUpdating = True
    End Sub

+ 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