Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Filter and delete

Posted on 2016-11-16
6
Medium Priority
?
34 Views
Last Modified: 2016-11-17
Can an expert provide me with VBA code that will filter then delete the data in that range but only that range.

So the range is A-N. I need to filter Column ‘I’ with Credit and then delete anything that now appears in that filter then unfilter.

There is a pivot table in cells R-S and I do not want to delete this.

I am using below code on other sheets where there is no pivot and this works fine but it deletes entire row.

Thank you in advance
0
Comment
Question by:Jagwarman
  • 5
6 Comments
 
LVL 53

Accepted Solution

by:
Rgonzo1971 earned 2000 total points
ID: 41890960
Hi,

pls try

Sub Macro1()
'
' Macro1 Macro
'
   Set c = Range("I" & Rows.Count)
   For lCol = 1 To WorksheetFunction.CountIf(Range("I:I"), "Credit")
        Set c = Range("I:I").Find(What:="Credit", LookAt:=xlWhole, SearchOrder:=xlByRows, SearchDirection:=xlNext, _
            MatchCase:=False)
            Range("A" & c.Row).Resize(, 14).Delete Shift:=xlShiftUp
   Next lCol
 
End Sub

Open in new window

Regards
0
 

Author Comment

by:Jagwarman
ID: 41890989
I don't understand it is giving me error "You cannot move a part of a pivot table and yet you are only looking upto 14 and the pivot is in 18 and 19. Any ideas?


 Range("A" & c.Row).Resize(, 14).Delete Shift:=xlShiftUp
0
 

Author Comment

by:Jagwarman
ID: 41891023
what I notice is if I right click my mouse on the range it does not show 'Delete' which would allow me to Shift cells UP/Down/Right/Left it only give me the option to Delete Row ???
0
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 

Author Comment

by:Jagwarman
ID: 41891030
reading up on this on Google looks like it's not possible it says you can only delete entire row when in filter mode. So now I have the problem I only want to delete from A-n where Credit is in column 'I'

What is the way around this?

Sorry Rgonzo, soon I will be gone
0
 

Author Comment

by:Jagwarman
ID: 41891034
Rgonzo, I think it is time for me to retire. Of course it was me, I just needed to remove the filter.

Regards
Jagwarman
0
 

Author Closing Comment

by:Jagwarman
ID: 41891035
:-)
0

Featured Post

Important Lessons on Recovering from Petya

In their most recent webinar, Skyport Systems explores ways to isolate and protect critical databases to keep the core of your company safe from harm.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In Part II of this series, I will discuss how to identify all open instances of Excel and enumerate the workbooks, spreadsheets, and named ranges within each of those instances.
Windows Explorer lets you open cabinet (cab) files like any other folder. In VBA you can easily handle normal files and folders, but opening and indeed creating cabinet files takes a lot more - and that's you'll find here.
Many functions in Excel can make decisions. The most simple of these is the IF function: it returns a value depending on whether a condition you describe is true or false. Once you get the hang of using the IF function, you will find it easier to us…
Have you created a query with information for a calendar? ... and then, abra-cadabra, the calendar is done?! I am going to show you how to make that happen. Visualize your data!  ... really see it To use the code to create a calendar from a q…

916 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question