macro help!!

seriouslystuck

Board Regular
Joined
Sep 24, 2009
Messages
97
Hi all

I need some help. Im trying to write a macro to clean up data in excel. What I want to do is if A1.value is =>D1 and =<C1 and H1.value is 0 the delete the row. I can write the loop to cycle through the rows but dont know how to write the rest.

Any help would be great

Thanks
 

Excel Facts

What did Pito Salas invent?
Pito Salas, working for Lotus, popularized what would become to be pivot tables. It was released as Lotus Improv in 1989.
Try a space after the < symbol, otherwise it gets treated as an invalid HTML-tag and gets stripped out
 
Upvote 0
For what range of rows do you want to run this check? Or is this variable and does the code need to find the last row itself?
 
Upvote 0
Try this:

Code:
Public Sub RemoveRows()
    Dim LastRow As Long
    Dim RowCounter As Long
    LastRow = Me.Cells(Me.Rows.Count, 1).End(xlUp).Row
    RowCounter = LastRow
    While RowCounter > 0
        If Me.Cells(RowCounter, 1).Value >= Me.Cells(RowCounter, 2).Value And _
            Me.Cells(RowCounter, 1).Value <= Me.Cells(RowCounter, 3).Value And _
            Me.Cells(RowCounter, 5).Value = "0" Then
            Me.Rows(RowCounter).Delete
        Else
            RowCounter = RowCounter - 1
        End If
    Wend
End Sub

You need to put that code in the worksheet code module where you want to run it. Also, use with care on a BACKUP of your data, I haven't tested it...
 
Upvote 0

Forum statistics

Threads
1,224,597
Messages
6,179,813
Members
452,945
Latest member
Bib195

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top