Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 504
Default code to remove rows containing a character string

I want to create a macro to remove all the rows of a table in which the cell
in column C contain "FM" within the text string. For some reason, when I set
up a macro to do a filter of "contains FM" then try to delete just those
rows, the macro deletes all rows.

After that ... I need to do the opposite. Need to delete all rows that does
NOT contain "FM".

Any help is appreciated.
  #2   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 11,501
Default code to remove rows containing a character string

Hi,

Right click your sheet tab, view code and paste this in and run it and all
rows with FM in the string in Col C will be deleted.

If you then to go on the delete all rows that don't contain FM all yoiur
data will be gone so I think you need to re-visit the second part of your
question

Sub delete_Me()
Dim copyrange As Range
Lastrow = Cells(Cells.Rows.Count, "C").End(xlUp).Row
Set MyRange = Range("C1:C" & Lastrow)
For Each c In MyRange
If InStr(c, "FM") Then 'Red change to suit
If copyrange Is Nothing Then
Set copyrange = c.EntireRow
Else
Set copyrange = Union(copyrange, c.EntireRow)
End If
End If
Next
If Not copyrange Is Nothing Then
copyrange.Delete
End If
End Sub

Mike


"kevin" wrote:

I want to create a macro to remove all the rows of a table in which the cell
in column C contain "FM" within the text string. For some reason, when I set
up a macro to do a filter of "contains FM" then try to delete just those
rows, the macro deletes all rows.

After that ... I need to do the opposite. Need to delete all rows that does
NOT contain "FM".

Any help is appreciated.

  #3   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 504
Default code to remove rows containing a character string

Worked great. I have two people working off this table. One of them works
with the ones containing "FM". The other works on those items not containing
"FM". My intent was to set up different macros for each to seperate the
lists out for them.

What changes would I make to delete those not containing "FM"?

Thanks again!

"Mike H" wrote:

Hi,

Right click your sheet tab, view code and paste this in and run it and all
rows with FM in the string in Col C will be deleted.

If you then to go on the delete all rows that don't contain FM all yoiur
data will be gone so I think you need to re-visit the second part of your
question

Sub delete_Me()
Dim copyrange As Range
Lastrow = Cells(Cells.Rows.Count, "C").End(xlUp).Row
Set MyRange = Range("C1:C" & Lastrow)
For Each c In MyRange
If InStr(c, "FM") Then 'Red change to suit
If copyrange Is Nothing Then
Set copyrange = c.EntireRow
Else
Set copyrange = Union(copyrange, c.EntireRow)
End If
End If
Next
If Not copyrange Is Nothing Then
copyrange.Delete
End If
End Sub

Mike


"kevin" wrote:

I want to create a macro to remove all the rows of a table in which the cell
in column C contain "FM" within the text string. For some reason, when I set
up a macro to do a filter of "contains FM" then try to delete just those
rows, the macro deletes all rows.

After that ... I need to do the opposite. Need to delete all rows that does
NOT contain "FM".

Any help is appreciated.

  #4   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 11,501
Default code to remove rows containing a character string

Kevin,

change this line

If InStr(c, "FM") Then

to This

If InStr(c, "FM") < 1 Then

Mike

"kevin" wrote:

Worked great. I have two people working off this table. One of them works
with the ones containing "FM". The other works on those items not containing
"FM". My intent was to set up different macros for each to seperate the
lists out for them.

What changes would I make to delete those not containing "FM"?

Thanks again!

"Mike H" wrote:

Hi,

Right click your sheet tab, view code and paste this in and run it and all
rows with FM in the string in Col C will be deleted.

If you then to go on the delete all rows that don't contain FM all yoiur
data will be gone so I think you need to re-visit the second part of your
question

Sub delete_Me()
Dim copyrange As Range
Lastrow = Cells(Cells.Rows.Count, "C").End(xlUp).Row
Set MyRange = Range("C1:C" & Lastrow)
For Each c In MyRange
If InStr(c, "FM") Then 'Red change to suit
If copyrange Is Nothing Then
Set copyrange = c.EntireRow
Else
Set copyrange = Union(copyrange, c.EntireRow)
End If
End If
Next
If Not copyrange Is Nothing Then
copyrange.Delete
End If
End Sub

Mike


"kevin" wrote:

I want to create a macro to remove all the rows of a table in which the cell
in column C contain "FM" within the text string. For some reason, when I set
up a macro to do a filter of "contains FM" then try to delete just those
rows, the macro deletes all rows.

After that ... I need to do the opposite. Need to delete all rows that does
NOT contain "FM".

Any help is appreciated.

  #5   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 504
Default code to remove rows containing a character string

Thanks a lot ... this worked perfect.

"Mike H" wrote:

Kevin,

change this line

If InStr(c, "FM") Then

to This

If InStr(c, "FM") < 1 Then

Mike

"kevin" wrote:

Worked great. I have two people working off this table. One of them works
with the ones containing "FM". The other works on those items not containing
"FM". My intent was to set up different macros for each to seperate the
lists out for them.

What changes would I make to delete those not containing "FM"?

Thanks again!

"Mike H" wrote:

Hi,

Right click your sheet tab, view code and paste this in and run it and all
rows with FM in the string in Col C will be deleted.

If you then to go on the delete all rows that don't contain FM all yoiur
data will be gone so I think you need to re-visit the second part of your
question

Sub delete_Me()
Dim copyrange As Range
Lastrow = Cells(Cells.Rows.Count, "C").End(xlUp).Row
Set MyRange = Range("C1:C" & Lastrow)
For Each c In MyRange
If InStr(c, "FM") Then 'Red change to suit
If copyrange Is Nothing Then
Set copyrange = c.EntireRow
Else
Set copyrange = Union(copyrange, c.EntireRow)
End If
End If
Next
If Not copyrange Is Nothing Then
copyrange.Delete
End If
End Sub

Mike


"kevin" wrote:

I want to create a macro to remove all the rows of a table in which the cell
in column C contain "FM" within the text string. For some reason, when I set
up a macro to do a filter of "contains FM" then try to delete just those
rows, the macro deletes all rows.

After that ... I need to do the opposite. Need to delete all rows that does
NOT contain "FM".

Any help is appreciated.

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
remove special character at end of string captain bob Excel Discussion (Misc queries) 0 August 3rd 06 02:59 PM
Remove last character of text string Grant Excel Worksheet Functions 2 September 29th 05 05:17 PM
Remove all characters following the first character in a string RC Excel Discussion (Misc queries) 5 August 30th 05 03:17 AM
want to remove all text characters equal to one character in length from text string [email protected] Excel Worksheet Functions 1 April 18th 05 09:56 PM
want to remove all text characters equal to one character in length from text string [email protected] Excel Worksheet Functions 1 April 18th 05 12:25 AM


All times are GMT +1. The time now is 04:25 PM.

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"