Comparing columns and deleting rows based on criteria

A

ALATL

I have the following columns that are a result of a pivot table. I would like
to delete the folllowing occurences. I tried using the range function but got
a runtime error 1004. Something like:

' If Not Range("Col1").Value Is Nothing Then
' Rows.Delete

Col1 Col2
a a b
X X X
X (delete)
X X
X X
X (delete)

I want to delete rows where Col1 = X and Col2 = X does not exist. To
complicate things, this is a pivot table where Col1 and Col2 are further
broken down into a and b. I thought that by using Range that a and b would
not need to be accounted for individually. Thanks for any help!
 
J

Jim Thomlinson

You can delete source data records of a pivot table (assuming the data is
sourced from the worksheet) but you can not delete any part of the pivot
table...
 
A

ALATL

Yes, I am aware of this. I did a copy and paste of the data to a new
worksheet. I am trying to delete the rows from the new worksheet.

Thanks!
 
J

Jim Thomlinson

This should be closer to what you want...

Dim rngToDelete As Range

On Error Resume Next
Set rngToDelete = Columns("A").SpecialCells(xlCellTypeBlanks)
On Error GoTo 0
If Not rngToDelete Is Nothing Then _
rngToDelete.EntireRow.Delete
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top