Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
DiscussionsAccessExcelInfoPathOutlookPowerPointPublisherWord
DirectoryUser Groups
Related Topics
Outlook ExpressInternet ExplorerWindowsMS Server ProductsMore Topics ...

MS Office Forum / Excel / Programming / March 2008

Tip: Looking for answers? Try searching our database.

delete rows that don't contain text

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Natdan - 25 Mar 2008 17:32 GMT
I have used subtotal on my data and have copied and paste special'd my data
to another sheet, I know want to delete all the rows that dont have the word
"*Total*" in them.  I am fairly new to vba and would appreciate any help
anyone can give me.
Ron de Bruin - 25 Mar 2008 17:45 GMT
See
http://www.rondebruin.nl/delete.htm

Try the AutoFilter example
http://www.rondebruin.nl/delete.htm#AutoFilter

Read the comments in the code

Signature

Regards Ron de Bruin
http://www.rondebruin.nl/tips.htm

>I have used subtotal on my data and have copied and paste special'd my data
> to another sheet, I know want to delete all the rows that dont have the word
> "*Total*" in them.  I am fairly new to vba and would appreciate any help
> anyone can give me.
ryguy7272 - 25 Mar 2008 19:23 GMT
I think this will do what you want:
Sub Delete_with_Autofilter()
   Dim DeleteValue As String
   Dim rng As Range

   DeleteValue = "*Total*"
   With ActiveSheet
       .Range("A1:A100").AutoFilter Field:=1, Criteria1:=DeleteValue
       With ActiveSheet.AutoFilter.Range
           On Error Resume Next
           Set rng = .Offset(1, 0).Resize(.Rows.Count - 1, 1) _
                     .SpecialCells(xlCellTypeVisible)
           On Error GoTo 0
           If Not rng Is Nothing Then rng.EntireRow.Delete

       End With
       .AutoFilterMode = False
   End With
End Sub

Notice:  the range is Column A, specifically A1:A100.  
Modify this to suit your needs.

Regards,
Ryan--

Signature

RyGuy

> See
> http://www.rondebruin.nl/delete.htm
[quoted text clipped - 8 lines]
> > "*Total*" in them.  I am fairly new to vba and would appreciate any help
> > anyone can give me.
Natdan - 25 Mar 2008 19:49 GMT
Thanks for your help guys
Ryan, that is actually the exact opposite of what I want to do, I actually
want to keep the rows that have the word total in them and delete the rest.  
when I subtotalled my data, then copied and pasted specialled it, the rows I
want to keep have cells that are e.g. "1 Total".

Ron I went to your website and followed some of the examples, I was able to
delete all the names except "ron" which is similar to what I want to do
except that I want to delete rows with cells like "1 total", but leave the
rows with "1"

Any help either of you can give me would be great.  

> I think this will do what you want:
> Sub Delete_with_Autofilter()
[quoted text clipped - 34 lines]
> > > "*Total*" in them.  I am fairly new to vba and would appreciate any help
> > > anyone can give me.
Ron de Bruin - 25 Mar 2008 21:10 GMT
>> want to keep the rows that have the word total in them and delete the rest.

Try
 DeleteValue = "<>*total*"

Like this

Sub Delete_with_Autofilter()
   Dim DeleteValue As String
   Dim rng As Range
   Dim calcmode As Long

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

   'Fill in the value that you want to delete
   'Tip: use DeleteValue = "<>ron" to delete rows without ron
   DeleteValue = "<>*total*"

   'Sheet with the data, you can also use Sheets("MySheet")
   With ActiveSheet

       'Firstly, remove the AutoFilter
       .AutoFilterMode = False

       'Apply the filter
       .Range("A1:A" & .Rows.Count).AutoFilter Field:=1, Criteria1:=DeleteValue

       With .AutoFilter.Range
           On Error Resume Next
           Set rng = .Offset(1, 0).Resize(.Rows.Count - 1, 1) _
                     .SpecialCells(xlCellTypeVisible)
           On Error GoTo 0
           If Not rng Is Nothing Then rng.EntireRow.Delete
       End With

       'Remove the AutoFilter
       .AutoFilterMode = False
   End With

   With Application
       .ScreenUpdating = True
       .Calculation = calcmode
   End With

End Sub

Signature

Regards Ron de Bruin
http://www.rondebruin.nl/tips.htm

> Thanks for your help guys
> Ryan, that is actually the exact opposite of what I want to do, I actually
[quoted text clipped - 47 lines]
>> > > "*Total*" in them.  I am fairly new to vba and would appreciate any help
>> > > anyone can give me.
Jarek Kujawa - 25 Mar 2008 21:20 GMT
try this one:

Sub test()
For Each cell In Selection
If cell Like "*Total*" Then
cell.Rows.EntireRow.Delete
End If
Next
End Sub
Ron de Bruin - 25 Mar 2008 21:24 GMT
Look out

If you delete rows start at the bottom and go up

Signature

Regards Ron de Bruin
http://www.rondebruin.nl/tips.htm

> try this one:
>
[quoted text clipped - 5 lines]
> Next
> End Sub
Jarek Kujawa - 25 Mar 2008 21:32 GMT
Ron, you're right
sorry
Natdan - 25 Mar 2008 21:37 GMT
Thanks Ron and Jarek

Ron your macro worked perfectly, I could not get Yours to work Jarek but
that probably me. I'm a complete novice. But enjoying the challenge

> try this one:
>
[quoted text clipped - 5 lines]
> Next
> End Sub
Jarek Kujawa - 25 Mar 2008 21:43 GMT
it's not you, it's my mistake
use Ron's pls
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.