Action on colored cell (1 Viewer)

DanG

Registered User.
Local time
Today, 08:48
Joined
Nov 4, 2004
Messages
477
I have a spreadsheet that someone has changed the row color on rows we want to delete.
Is there a way to delete any row that is say...yellow for example?
I do not know excel vba at all FYI.

Thank you
 

Brianwarnock

Retired
Local time
Today, 16:48
Joined
Jun 2, 2003
Messages
12,701
As this thread is old maybe your problem is solved, but if not then you must, I believe, use code.
The code below should be copied into a module and works as follows

Select a cell that contains the colour of the rows you wish to delete
Run the macro

Code:
Sub deletebycolour()

'Brian Warnock  20/09/06

Dim lngCounter As Long
Dim lngLastRow As Long

ci = ActiveWindow.RangeSelection.Interior.ColorIndex

With ActiveSheet.UsedRange
lngLastRow = .Cells(1, 1).Row + .Rows.Count - 1
End With

lngCounter = 1

Application.ScreenUpdating = False
Do While lngCounter <= lngLastRow
Set r = Range("a1")
 If r.Cells(lngCounter, 1).Interior.ColorIndex = ci Then
 Rows(lngCounter).Delete
 lngCounter = lngCounter
 lngLastRow = lngLastRow - 1
 Else
 lngCounter = lngCounter + 1
End If
 
Loop
Application.ScreenUpdating = True
End Sub

Just in case, to copy the code into a module Alt+F11 opens up the VBA editor, you should see your spreadsheet listed on the left in the project pane, if not Ctrl+r will open that then Insert module from the menu bar and drop down will give you a module to cut and paste the code into

Best of luck

Brian
 

Users who are viewing this thread

Top Bottom