Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.worksheet.functions
external usenet poster
 
Posts: 1
Default A macro for deleting lines of text

Hi I need to delete all lines except those containing the Text NMI, FromDate,
To Date

Can someone tell me where I'm going wrong with this Macro when I run it, it
deletes all lines?

Public Sub DeleteNonSpecific Rows()
Dim rCell As Range
Dim rDelete As Range

For Each rCell In Range("A1:A" & _
Range("A" & Rows.Count).End(xlUp).Row)
With rCell
If Not (Text) = " FromDate" Or _
(Text) = " ToDate" Or _
UCase(.Text) = " NMI ") Then
If rDelete Is Nothing Then
Set rDelete = .Cells
Else
Set rDelete = Union(rDelete, .Cells)
End If
End If
End With
Next rCell
If Not rDelete Is Nothing Then rDelete.EntireRow.Delete
End Sub

  #2   Report Post  
Posted to microsoft.public.excel.worksheet.functions
external usenet poster
 
Posts: 2,510
Default A macro for deleting lines of text

Hi Melara,

You have some parenthesis in the wrong place and leading dots missing from
..Text After fixing these the code seems to test OK. However, the leading and
trailing spaces in the text being compared worry me so below is your code
simply corrected and below that I have included a line where I would use
Instr function and leave the leading and trailing spaces off the strings to
look for.

Public Sub DeleteNonSpecificRows()
Dim rCell As Range
Dim rDelete As Range

For Each rCell In Range("A1:A" & _
Range("A" & Rows.Count).End(xlUp).Row)
With rCell
If Not (.Text = " FromDate" Or _
.Text = " ToDate" Or _
UCase(.Text) = " NMI ") Then
If rDelete Is Nothing Then
Set rDelete = .Cells
Else
Set rDelete = Union(rDelete, .Cells)
End If
End If
End With
Next rCell

If Not rDelete Is Nothing Then rDelete.EntireRow.Delete

End Sub


Using Instr function for the test.

If Not (InStr(.Text, "FromDate") 0 Or _
InStr(.Text, "ToDate") 0 Or _
InStr(UCase(.Text), "NMI") 0) Then


--
Regards,

OssieMac


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
DELETING LINES THAT ARE THE SAME IN A TABLE conditional format if cell contains word[_2_] Excel Discussion (Misc queries) 1 May 28th 09 03:04 AM
Deleting lines that use them for formulas OX_Gambit Excel Discussion (Misc queries) 4 April 2nd 09 01:30 PM
Deleting unused lines between used lines? Stevel Setting up and Configuration of Excel 1 November 25th 05 12:58 AM
Deleting Lines in Excel sibadee14 Excel Discussion (Misc queries) 1 November 16th 05 06:56 AM
Deleting multiple lines tammytlc Excel Discussion (Misc queries) 1 October 3rd 05 11:49 PM


All times are GMT +1. The time now is 12:18 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"