Wow!!! That works like a charm.
Thank you very much for the quick reply.![]()
Wow!!! That works like a charm.
Thank you very much for the quick reply.![]()
Hi, johnny_tc,
you´re welcome. If your question has been answered please mark the thread as solved (Thread Tools opening post).
TIA
Holger
A small issue came up. I just modified the Case terms to find text of my choice.
Now when i am running the macro, it is showing "Compile error: Invalid or unqualified reference"
Any idea what the problem could be?Below is how i edited your code:
![]()
Sub DeletePublicationType() Dim lngCounter As Long Dim lngLastRow As Long Dim rngFound As Range Const cstrSEARCH As String = "Publication Type" Sheets("Raw Data").Select Set rngFound = .Rows("1:1").Find(what:=cstrSEARCH, _ LookIn:=xlValues, lookat:=xlWhole, searchorder:=xlByColumns) If Not rngFound Is Nothing Then lngLastRow = .Cells(Rows.Count, rngFound.Column).End(xlUp).Row For lngCounter = lngLastRow To 2 Step -1 Select Case (.Cells(lngCounter, rngFound.Column).Value) Case "Country Business Guide", "Country HR Web Guide", "Country Guide", "Country Snapshot", "Business Guide" Rows(lngCounter).Delete Case Else 'keep record End Select Next lngCounter End If End With Set rngFound = Nothing End Sub
Hi, johnny_tc,
I used an With...End With and referred to the sheet within the (no need for the sheet to be activates).
You select the sheet so any information on Rows, Columns, cells, Ranges is lost. That´s the reason for your run time error.
If you want to go on with
just add the line directly beneath that line of Code![]()
Sheets("Raw Data").Select
and leave everything else as it was.![]()
With ActiveSheet
Or you have a go with
Ciao,![]()
Sub DeletePublicationType() Dim lngCounter As Long Dim lngLastRow As Long Dim rngFound As Range Const cstrSEARCH As String = "Publication Type" Sheets("Raw Data").Select Set rngFound = Rows("1:1").Find(what:=cstrSEARCH, _ LookIn:=xlValues, lookat:=xlWhole, searchorder:=xlByColumns) If Not rngFound Is Nothing Then lngLastRow = Cells(Rows.Count, rngFound.Column).End(xlUp).Row For lngCounter = lngLastRow To 2 Step -1 Select Case (Cells(lngCounter, rngFound.Column).Value) Case "Country Business Guide", "Country HR Web Guide", "Country Guide", "Country Snapshot", "Business Guide" Rows(lngCounter).Delete Case Else 'keep record End Select Next lngCounter End If Set rngFound = Nothing End Sub
Holger
Last edited by HaHoBe; 08-23-2012 at 07:18 AM. Reason: maybe better explanation
Wonderful!!!
Thank you once again..!!!
Hi,
I Just used your code to delete some rows from a specified column, however if i wanted to use a wildcard search in a particular column for example (from above) find any cell that contains the word "country" then delete that row. How would you that do that please?
Hi, mazrientes,
welcome to ExcelForum. Please note that according to Rule #2 you should start your own thread with your question.
I´d rely on the Autofilter for this kind of problem (use "contains" for the item you search for) instead of a loop with wildcards. And if you want a loop alter the parameter from lookat:=xlWhole to lookat:=xlPart.
Ciao,
Holger
Use Code-Tags for showing your code: [code] Your Code here [/code]
Please mark your question Solved if there has been offered a solution that works fine for you
There are currently 1 users browsing this thread. (0 members and 1 guests)
Bookmarks