+ Reply to Thread
Results 1 to 4 of 4

VBA that will delete entire row and shift cells up based on previous columns cell values

Hybrid View

  1. #1
    Registered User
    Join Date
    11-06-2012
    Location
    Chicago, Illinois
    MS-Off Ver
    Excel 2003
    Posts
    2

    VBA that will delete entire row and shift cells up based on previous columns cell values

    Hi all,
    I understand that there is no excel formula that will delete an entire row of information. However, I was hoping that there is a VBA that will perform this task. In my example, the first column contains dates, and the second and third contains certain "triggers" that will notify the user whether or not to trade stocks. I was hoping to input a code that will analyze these latter two columns and, if in any given row both cells have the value 0, delete the entire row and shift the following rows up. Below is a sample of what my spreadsheet looks like. For this example, the row with the date 1/4/12 would be deleted since it contains 0 in both trigger columns.

    Date Trigger A Trigger B
    1/1/2012 0 1
    1/2/2012 1 0
    1/3/2012 1 1
    1/4/2012 0 0
    1/5/2012 0 1
    1/6/2012 1 0
    1/7/2012 1 1
    1/8/2012 1 1
    1/9/2012 1 0
    1/10/2012 0 1

    Any help with this would be much appreciated.

    Cheers,
    John

  2. #2
    Forum Expert
    Join Date
    03-28-2012
    Location
    TBA
    MS-Off Ver
    Office 365
    Posts
    12,454

    Re: VBA that will delete entire row and shift cells up based on previous columns cell valu

    You mean like this

    Sub Macro1()
    Dim LR As Long, i As Long
     Application.DisplayAlerts = False
     With ActiveSheet
     LR = .Cells.Find(what:="*", searchorder:=xlByRows, SearchDirection:=xlPrevious).Row
     For i = LR To 2 Step -1
     On Error Resume Next
        If (Cells(i, 2).Value) = 0 And (Cells(i, 3).Value) = 0 Then Rows(i).Delete SHIFT:=xlUp
     Next i
     End With
     Application.DisplayAlerts = True
     End Sub

  3. #3
    Registered User
    Join Date
    11-06-2012
    Location
    Chicago, Illinois
    MS-Off Ver
    Excel 2003
    Posts
    2

    Re: VBA that will delete entire row and shift cells up based on previous columns cell valu

    Great! That's exactly what I was looking for. Thanks a lot, I appreciate it.

  4. #4
    Forum Expert
    Join Date
    03-28-2012
    Location
    TBA
    MS-Off Ver
    Office 365
    Posts
    12,454

    Re: VBA that will delete entire row and shift cells up based on previous columns cell valu

    Glad to be helpful!

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

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