Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3
Default delete rows that don't contain text

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.
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,123
Default delete rows that don't contain text

See
http://www.rondebruin.nl/delete.htm

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

Read the comments in the code

--

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


"Natdan" wrote in message ...
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.

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,836
Default delete rows that don't contain text

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--


--
RyGuy


"Ron de Bruin" wrote:

See
http://www.rondebruin.nl/delete.htm

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

Read the comments in the code

--

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


"Natdan" wrote in message ...
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.


  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3
Default delete rows that don't contain text

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.

"ryguy7272" wrote:

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--


--
RyGuy


"Ron de Bruin" wrote:

See
http://www.rondebruin.nl/delete.htm

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

Read the comments in the code

--

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


"Natdan" wrote in message ...
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.


  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,123
Default delete rows that don't contain text

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


--

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


"Natdan" wrote in message ...
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.

"ryguy7272" wrote:

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--


--
RyGuy


"Ron de Bruin" wrote:

See
http://www.rondebruin.nl/delete.htm

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

Read the comments in the code

--

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


"Natdan" wrote in message ...
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.



  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 896
Default delete rows that don't contain text

try this one:

Sub test()
For Each cell In Selection
If cell Like "*Total*" Then
cell.Rows.EntireRow.Delete
End If
Next
End Sub
  #7   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,123
Default delete rows that don't contain text

Look out

If you delete rows start at the bottom and go up

--

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


"Jarek Kujawa" wrote in message ...
try this one:

Sub test()
For Each cell In Selection
If cell Like "*Total*" Then
cell.Rows.EntireRow.Delete
End If
Next
End Sub

  #8   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 896
Default delete rows that don't contain text

Ron, you're right
sorry
  #9   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3
Default delete rows that don't contain text

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

"Jarek Kujawa" wrote:

try this one:

Sub test()
For Each cell In Selection
If cell Like "*Total*" Then
cell.Rows.EntireRow.Delete
End If
Next
End Sub

  #10   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 896
Default delete rows that don't contain text

it's not you, it's my mistake
use Ron's pls
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 with certain text Pete Excel Worksheet Functions 2 July 5th 06 04:03 PM
Delete rows with numeric values, leave rows with text GSpline Excel Programming 5 October 11th 05 12:44 AM
delete empty rows between rows with text Paulo Baptista Excel Discussion (Misc queries) 2 February 28th 05 03:41 PM
Excel VBA - Delete Rows with certain text... JMax Excel Programming 0 February 18th 04 09:58 PM
Delete rows that DO NOT contain certain text Steph[_3_] Excel Programming 9 January 20th 04 06:53 PM


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