Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2
Default This should be simple but...

I have a spreadsheet with thousands of lines of data
I need to remove some lines of data

The rule is...
If any cell in column A has a background colour that's not the default
(blank) then delete the whole row.

I know this should be a simple loop but recording a macro doesn't seem to
give me any clues. Any help would be appreciated.

Jeff

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default This should be simple but...

Jeff, if I understood you correctly this should do the trick:

Sub erase_rows()
lastrow = ActiveSheet.UsedRange.Rows.Count
For i = lastrow To 1 Step -1
cell = "A" & i
Range(cell).Select
If Selection.Interior.ColorIndex < xlNone Then
Rows(i).Select
Selection.Delete Shift:=xlUp
End If
Next i
End Sub

"Jeff" wrote:

I have a spreadsheet with thousands of lines of data
I need to remove some lines of data

The rule is...
If any cell in column A has a background colour that's not the default
(blank) then delete the whole row.

I know this should be a simple loop but recording a macro doesn't seem to
give me any clues. Any help would be appreciated.

Jeff


  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 21
Default This should be simple but...

Jeff

Something like this should work. Cells with the default background (pattern?)
have the PatternColorIndex of -4142, not my first guess but I was able to use
the immediate pane to find out). Select the applicable rows and run this
simple code.

Sub test()

Dim cl As Range

For Each cl In Selection
If Not (cl.Interior.PatternColorIndex = -4142) Then cl.EntireRow.Delete
Next cl

End Sub

Good luck.

Ken
Norfolk, Va
  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2
Default This should be simple but...

Thanks Ken

That worked reasonably

For some reason, deleting rows from the selection made the macro "jump"
rows, but I got round that by simply running the macro 50 times!

Job done thanks.
I'll now go away and brush up on how to retrieve cell properties.


Jeff

Jeff

Something like this should work. Cells with the default background
(pattern?)
have the PatternColorIndex of -4142, not my first guess but I was able to
use
the immediate pane to find out). Select the applicable rows and run this
simple code.

Sub test()

Dim cl As Range

For Each cl In Selection
If Not (cl.Interior.PatternColorIndex = -4142) Then
cl.EntireRow.Delete
Next cl

End Sub

Good luck.

Ken
Norfolk, Va



Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
IF formula-simple question; simple operator Rich D Excel Discussion (Misc queries) 4 December 6th 07 03:36 PM
Simple problem, simple formula, no FUNCTION ! Ron@Buy Excel Worksheet Functions 6 September 28th 07 04:51 PM
Simple Simple Excel usage question BookerW Excel Discussion (Misc queries) 1 June 23rd 05 10:06 PM
Make it more simple or intuitive to do simple things Vernie Charts and Charting in Excel 1 March 16th 05 04:01 AM
simple question, hopefully a simple answer! Matt B Excel Programming 5 January 13th 04 08:43 PM


All times are GMT +1. The time now is 04:59 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"