Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 49
Default Delete rows if range is null and not in color...

My spreadsheets has rows that are in color w/null values. There are others
that are just null and no color. I need to figure out how to delete only the
rows that have nulls, but not the ones that have color and also null. I have
searched and can't find quite the right response to my question. Thanks for
the help.

Jeremiah
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 6,953
Default Delete rows if range is null and not in color...

Sub ABC()
Dim cell As Range, r1 As Range
For Each cell In Range("A1:A500")
If cell.Interior.ColorIndex = xlNone Then
If Len(Trim(cell.Text)) = 0 Then
If r1 Is Nothing Then
Set r1 = cell
Else
Set r1 = Union(r1, cell)
End If
End If
End If
Next
If Not r1 Is Nothing Then
r1.EntireRow.Delete
End If

End Sub

worked for me. Assumes the interior color is not produced by conditional
formatting.

--
Regards,
Tom Ogilvy


"jeremiah" wrote:

My spreadsheets has rows that are in color w/null values. There are others
that are just null and no color. I need to figure out how to delete only the
rows that have nulls, but not the ones that have color and also null. I have
searched and can't find quite the right response to my question. Thanks for
the help.

Jeremiah

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,939
Default Delete rows if range is null and not in color...

How about this...

Sub test()
Dim rngUsed As Range
Dim rng As Range
Dim rngColour As Range
Dim rngToDelete As Range
Dim blnColour As Boolean

Set rngUsed = UsedRange.Columns(1).Cells
For Each rng In rngUsed
If Application.WorksheetFunction.CountA(rng.EntireRow ) = 0 Then
For Each rngColour In rng.EntireRow.Cells
If rngColour.Interior.ColorIndex < xlNone Then
blnColour = True
'Exit For
End If
Next rngColour
If blnColour = False Then
If rngToDelete Is Nothing Then
Set rngToDelete = rng
Else
Set rngToDelete = Union(rng, rngToDelete)
End If
End If
blnColour = False
End If
Next rng
If Not rngToDelete Is Nothing Then rngToDelete.EntireRow.Select
End Sub
--
HTH...

Jim Thomlinson


"jeremiah" wrote:

My spreadsheets has rows that are in color w/null values. There are others
that are just null and no color. I need to figure out how to delete only the
rows that have nulls, but not the ones that have color and also null. I have
searched and can't find quite the right response to my question. Thanks for
the help.

Jeremiah

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,939
Default Delete rows if range is null and not in color...

Sorry change the select to a delete and remove the comment on the exit for

Sub test()
Dim rngUsed As Range
Dim rng As Range
Dim rngColour As Range
Dim rngToDelete As Range
Dim blnColour As Boolean

Set rngUsed = UsedRange.Columns(1).Cells
For Each rng In rngUsed
If Application.WorksheetFunction.CountA(rng.EntireRow ) = 0 Then
For Each rngColour In rng.EntireRow.Cells
If rngColour.Interior.ColorIndex < xlNone Then
blnColour = True
Exit For
End If
Next rngColour
If blnColour = False Then
If rngToDelete Is Nothing Then
Set rngToDelete = rng
Else
Set rngToDelete = Union(rng, rngToDelete)
End If
End If
blnColour = False
End If
Next rng
If Not rngToDelete Is Nothing Then rngToDelete.EntireRow.Delete
End Sub
--
HTH...

Jim Thomlinson


"Jim Thomlinson" wrote:

How about this...

Sub test()
Dim rngUsed As Range
Dim rng As Range
Dim rngColour As Range
Dim rngToDelete As Range
Dim blnColour As Boolean

Set rngUsed = UsedRange.Columns(1).Cells
For Each rng In rngUsed
If Application.WorksheetFunction.CountA(rng.EntireRow ) = 0 Then
For Each rngColour In rng.EntireRow.Cells
If rngColour.Interior.ColorIndex < xlNone Then
blnColour = True
'Exit For
End If
Next rngColour
If blnColour = False Then
If rngToDelete Is Nothing Then
Set rngToDelete = rng
Else
Set rngToDelete = Union(rng, rngToDelete)
End If
End If
blnColour = False
End If
Next rng
If Not rngToDelete Is Nothing Then rngToDelete.EntireRow.Select
End Sub
--
HTH...

Jim Thomlinson


"jeremiah" wrote:

My spreadsheets has rows that are in color w/null values. There are others
that are just null and no color. I need to figure out how to delete only the
rows that have nulls, but not the ones that have color and also null. I have
searched and can't find quite the right response to my question. Thanks for
the help.

Jeremiah

  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 49
Default Delete rows if range is null and not in color...

I know I should have posted the code I currently have working thanks to Ron
DeBruin. I neglected to mention that my blanks would be in specific columns
so I cannot look at the entire spreadsheet. How can I ignore those cells
that have color?
Sub Loop_Example2()
Dim Firstrow As Long
Dim Lastrow As Long
Dim Lrow As Long
Dim CalcMode As Long
Dim ViewMode As Long

With Application
CalcMode = .Calculation
.Calculation = xlCalculationManual
.ScreenUpdating = False
End With

With ActiveSheet

.Select

ViewMode = ActiveWindow.View
ActiveWindow.View = xlNormalView

.DisplayPageBreaks = False

Firstrow = .UsedRange.Cells(1).Row
Lastrow = .UsedRange.Rows(.UsedRange.Rows.Count).Row

For Lrow = Lastrow To Firstrow Step -1

If .Cells(Lrow, "c").Value = 0 And _
.Cells(Lrow, "f").Value = 0 And _
.Cells(Lrow, "i").Value = 0 And _
.Cells(Lrow, "l").Value = 0 And _
.Cells(Lrow, "o").Value = 0 Then .Rows(Lrow).Delete

Next Lrow

End With

ActiveWindow.View = ViewMode
With Application
.ScreenUpdating = True
.Calculation = CalcMode
End With

End Sub



"Jim Thomlinson" wrote:

Sorry change the select to a delete and remove the comment on the exit for

Sub test()
Dim rngUsed As Range
Dim rng As Range
Dim rngColour As Range
Dim rngToDelete As Range
Dim blnColour As Boolean

Set rngUsed = UsedRange.Columns(1).Cells
For Each rng In rngUsed
If Application.WorksheetFunction.CountA(rng.EntireRow ) = 0 Then
For Each rngColour In rng.EntireRow.Cells
If rngColour.Interior.ColorIndex < xlNone Then
blnColour = True
Exit For
End If
Next rngColour
If blnColour = False Then
If rngToDelete Is Nothing Then
Set rngToDelete = rng
Else
Set rngToDelete = Union(rng, rngToDelete)
End If
End If
blnColour = False
End If
Next rng
If Not rngToDelete Is Nothing Then rngToDelete.EntireRow.Delete
End Sub
--
HTH...

Jim Thomlinson


"Jim Thomlinson" wrote:

How about this...

Sub test()
Dim rngUsed As Range
Dim rng As Range
Dim rngColour As Range
Dim rngToDelete As Range
Dim blnColour As Boolean

Set rngUsed = UsedRange.Columns(1).Cells
For Each rng In rngUsed
If Application.WorksheetFunction.CountA(rng.EntireRow ) = 0 Then
For Each rngColour In rng.EntireRow.Cells
If rngColour.Interior.ColorIndex < xlNone Then
blnColour = True
'Exit For
End If
Next rngColour
If blnColour = False Then
If rngToDelete Is Nothing Then
Set rngToDelete = rng
Else
Set rngToDelete = Union(rng, rngToDelete)
End If
End If
blnColour = False
End If
Next rng
If Not rngToDelete Is Nothing Then rngToDelete.EntireRow.Select
End Sub
--
HTH...

Jim Thomlinson


"jeremiah" wrote:

My spreadsheets has rows that are in color w/null values. There are others
that are just null and no color. I need to figure out how to delete only the
rows that have nulls, but not the ones that have color and also null. I have
searched and can't find quite the right response to my question. Thanks for
the help.

Jeremiah

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
Delete Rows Based on highlighted Color Neon520 Excel Discussion (Misc queries) 7 March 28th 09 08:56 AM
Delete Null/Blank Rows Theresa Excel Discussion (Misc queries) 8 December 18th 07 05:17 AM
code to delete null rows after criteria found tbmarlie Excel Programming 5 October 11th 07 11:35 PM
vba code to delete null rows after criteria found tbmarlie Excel Programming 1 October 11th 07 02:17 PM
delete rows with null values in "M" column Janis Excel Programming 5 July 18th 07 09:48 PM


All times are GMT +1. The time now is 02:16 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"