Hi,
I'm very new to VBA programming for excel macros and I need some help. I'm trying to get Excel to delete entire rows based on the conditional formating i'm using.
Basically, I want to get rid of all the rows that are of a certain color (let's say green, InteriorColor = 4). I've already come up with a way to delete rows based on color, but I have to take into account the Conditional formating i'm using.
Here's what I already have:
Any help would be awesome. Thanks!Option Explicit Sub DeleteGreenRows() Dim LR As Long, a As Long Application.ScreenUpdating = False LR = Cells(Rows.Count, 1).End(xlUp).Row For a = LR To 1 Step -1 If Cells(a, 1).FormatConditions.InteriorColor = 4 Then Rows(a).EntireRow.Delete End If Next a Application.ScreenUpdating = True End Sub
Last edited by Yobari; 06-11-2009 at 11:22 AM.
A better approach would be to put the conditional formatting formula in a separate column, and use that for both conditional formatting and as the test criteria for deletion.
Please change your QUOTE tags to CODE tags.
Microsoft MVP - Excel
Entia non sunt multiplicanda sine necessitate
Alright, i didn't notice the CODE tags, sorry!
I've included the file i'm using to test this macro on, it will obviously be used on a much bigger database export.
I changed it so the conditional formating's function is in a separate column (which makes a lot of sense). But I'm a little confused as to what I should base the If Cells verification on or if it's a completely different way of doing it.
The conditional format would be Formula is =B1 or =NOT(B1), depending on what you want.
Microsoft MVP - Excel
Entia non sunt multiplicanda sine necessitate
Yeah, the conditional formating wasn't really all that important, I was just looking at a way to identify the cells that are in both lists and then be able to delete them.
What I'm asking about is how I can delete the rows where the value of the column B is FALSE (meaning that these values are in both lists).
I thought I could use the code in the first post and modify it so that it would delete the rows where Cells(a,2) = "FALSE" but I seem to be missing something.
You can. Post the revised code.
Microsoft MVP - Excel
Entia non sunt multiplicanda sine necessitate
I know I'm missing something between Cells(a, 2) and the =Option Explicit Sub DeleteFalseRows() Dim LR As Long, a As Long Application.ScreenUpdating = False LR = Cells(Rows.Count, 2).End(xlUp).Row For a = LR To 1 Step -1 If Cells(a, 2) = "FALSE" Then Rows(a).EntireRow.Delete End If Next a Application.ScreenUpdating = True End Sub
Sub DeleteFalseRows() Dim iRow As Long With Application .ScreenUpdating = False .Calculation = xlCalculationManual For iRow = Cells(Rows.Count, 2).End(xlUp).Row To 1 Step -1 If Cells(iRow, 2).Value = False Then Rows(iRow).Delete Next iRow .ScreenUpdating = True .Calculation = xlCalculationAutomatic End With End Sub
Microsoft MVP - Excel
Entia non sunt multiplicanda sine necessitate
Awesome.
Why are you changing the .Calculation to manual though? It works without it.
When you delete a row, Excel automatically recalculates. There no need for it, and it will slow things down.
There is likewise no need to turn screenupdating off.
Would you please mark the thread as Solved?
Microsoft MVP - Excel
Entia non sunt multiplicanda sine necessitate
Yeah, I realized that when I tried it with a 28k row worksheet, you're better off turning it off.
Thanks for everything!
There are currently 1 users browsing this thread. (0 members and 1 guests)
Bookmarks