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

0
Utf
1/4/2010 5:22:01 AM
excel.worksheet.functions 4936 articles. 2 followers. Follow

1 Replies
1610 Views

Similar Articles

[PageSpeed] 33

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


0
Utf
1/4/2010 7:29:01 AM
Reply:

Similar Artilces:

Macro warning with no macros
I have a workbook that when I try to open it I get the warning tellin me it contains macros and asking whether I want to Enable or Disabl them. I put no macros, no VB scripts, nothing at all in the workboo other than standard Excel formulas and some charts. I developed it i Excel 2002, SP-2, but have moved it back and forth between tw computers, the other which has Excel 97. Regardless of whether Enable or Disable or change the security settings so as not to get th warning, once the workbook is open even if I go t Tools-Macro-Macros... it lists no macros. How can I find out what's cau...

deleting rows #4
In microsoft encell 2000 when i delete a row (say row 5) the row disapears but so does the row number then all other rows are moved up is there a way to delete the row and keep the number 5? The row number shouldn't disappear unless you are hiding the row, not deleting it -- HTH Nick Hodge Microsoft MVP - Excel Southampton, England nick_hodgeTAKETHISOUT@zen.co.uk.ANDTHIS "Doctorpc631" <doctorpc631@aol.com> wrote in message news:e4FaNYV4EHA.1260@TK2MSFTNGP12.phx.gbl... > In microsoft encell 2000 when i delete a row (say row 5) the row > disapears > but s...

Why do legacy checkboxes freeze text fields in Word 2007?
If you use "Legacy Controls" checkboxes in Word 2007 and you have plain text or rich text fields, when you protect the document it will freeze you out of text fields after you select a checkbox. It only seems to do this with more than four or five check boxes and more than four or five text boxes. Help, anyone? Legacy fields require the document to be protected. Word 2007 content controls require it to be unprotected, thus the two are incompatible in the same document. -- <>>< ><<> ><<> <>>< ><<> <>...

Macro
Can anybody tell me how to kick off a macro automatically as file is opened? Regards ...

Shade under a line
I have scatterplots with date/time along the X axis, and data on the Y axis. I'd like to add shading from sunrise to sunset. I can create a line on the scatterplot that is 0 during the day and a value greater than the max Y value at night, but would like to be able to shade under this line to more easily visualize when it's dark. I also tried creating a bar graph in the background on a second X axis, thinking I could have small categories with date and light/dark data, but the time axis cannot do increments smaller than days, so that hasn't worked. Any suggestions? I ha...

Macro
Version: 2008 Operating System: Mac OS X 10.4 (Tiger) Processor: intel Hi, I'm thinking of buying Mac: Office 2008, but before I do I want to check that I will be able to download Scritpsmart collection of templates without any glitches: <http://www.bbc.co.uk/writersroom/scriptsmart/faq.shtml> Does anyone know if I can do this? Regards, SP. In article <ee98ff5.-1@webcrossing.caR9absDaxw>, StregaItalia@officeformac.com wrote: > Version: 2008 > Operating System: Mac OS X 10.4 (Tiger) > Processor: intel > > Hi, > > I'm thinking of buying Mac: Of...

Let me use the Line Color icon on charts
It would speed up a lot of my work if I could use the Line Color icon on Excel charts, the same way I am able to use the Fill Color and Font Color icons. However, when I highlight any chart object, like the Plot Area, Chart Area, or a Series, the Line Color icon is disabled. -- Stuart Bratesman, Jr., MPP Muskie School of Public Service Univ. of Southern Maine Portland, Maine ---------------- This post is a suggestion for Microsoft, and Microsoft responds to the suggestions with the most votes. To vote for this suggestion, click the "I Agree" button in the message pane. If ...

Run macro automatically.
How do I make a macro run automatically when a worksheet it is attached to is loaded? right click on the sheet tab>view code>left window worksheet>right window activate -- Don Guillett SalesAid Software donaldb@281.com "Excel macro" <Excel macro@discussions.microsoft.com> wrote in message news:DD7AF1E3-9263-4523-AC49-A43ABA1AB9D0@microsoft.com... > How do I make a macro run automatically when a worksheet it is attached to is > loaded? I am unable to find "activate " when I right click on worksheet. ( i assume that you are referring to the windo...

Help with macro/and or formula?
Perhaps this is a silly question, but i just can't figure out how t format this worksheet. The problem is that a lot of the cells hav numbers in them with negative signs in the back instead of in the fron (ie. 23-) and i was wondering if anyone knew of a macro/formula i coul use to quickly fix this problem for all the cells. I would b extremely grateful. Thanks -- brefed1 ----------------------------------------------------------------------- brefed15's Profile: http://www.excelforum.com/member.php?action=getinfo&userid=3557 View this thread: http://www.excelforum.com/showthre...

Attached Toolbars Macros
Excel 2003 I have a custom tool bar, this tool bar has several items, each item is pointing to a VBA code. This tool bar is attached to the worksheet. I've copied this spreadsheet to several computers. After I copied the spreadsheet I decided to rename the spreadsheet, after I renamed the spreadsheet the Toolbar Item's macros were still pointing to the old name, I reasigned each tool bar item to the current spreadsheet, saved the spreadsheet and everything was working on my computer, but when I re-copied the new spreadsheet to other computers and I clicked on the Toolbar Item...

Troubleshooting Delete #2
Roady - I thought originally I had said I was trying to delete an old message from Outbox in Outlook. It will not delete and says that "mapi spooler" whatever and has originally begun transmitting. I have tried to put Outlook in offline work mode, it will still not delete. I have tried to move the message to another folder, but it will not move. Outlook would go back online by itself. So, then, I tried disconnecting the cable for the internet, restarted, and tried to delete again. No go. I browsed other discussions and saw that you had recommended using a shift delete. This a...

Deleting Unusual Recurrence of a scheduled item.
Hello, I have a strange problem. Somehow, I have an event that recurs every day until Dec 22 2005. I have no idea how this happened, but when I delete one, I don't get any message about deleting the series, meaning I have to delete this entry for each day from here to Dec 22 2005. The easy way is of course, to ignore the entry, but I would really like to clean it up. Any ideas how to do this? Thanks! Rick RWC <rcollens_SPAMONATOR_@hemmingway.com> wrote: > I have a strange problem. Somehow, I have an event that recurs every > day until Dec 22 2005. I have no ide...

Protected sheets and running macros
i have a sheet with a macro ran by a normal button at the top. Howeve when i protect the worksheet where ever i click on the sheet the macr executes. Can any one offer any advice on how to stop this? Thanks Robert -- Message posted from http://www.ExcelForum.com hi, i am not able to reproduce the problem, hence i may not be able t provide a panacea for that issue. here is what i suggest. i have a sheet that has a macro that is run when a control toolbo button (that is, not a form button) is clicked. this sheet is protected based on the user logged in. what i have don is to protect t...

Macro to remove rows?
Hi, I receive thousands of rows of data from an extract that comes from a database. The data extract automatically generates page headers that need to be removed, and I would love to automate this process. The headers do have a pattern to them, but I'm not clever enough to figure out a good way to use that to write a macro. The first row of the header starts with hyphens ------------------------------- Then there's a variable number of rows of header data to delete followed by another row of hyphens ------------------------------- Then 2 additional rows that must be deleted. The nu...

Macro Freezes Reading Pane
I have a macro that Sends/Receives Tasks from Project Server into Outlook Tasks. Everything is working fine, except one weird thing that happens. I have the Timer set on the macro and it starts as soon as Outlook starts. The macro gets the tasks from ProjectServer every hour. As soon as the macro starts running the Reading pane freezes in the Inbox. If i stop the macro then Reading pane is back to normal. Can anyone please tell me if there is something I can do in VBA to fix this annoying issue. Thanks a lot ...

What is CV text?
Can someone tell me what CV text is? Do you mean CSV, comma separated values? -- HTH RP "Tina" <Tina@discussions.microsoft.com> wrote in message news:ED97A150-9075-4251-8739-1E73F647527C@microsoft.com... > Can someone tell me what CV text is? And if you did mean CSV (comma separated values), then the name is pretty descriptive. But if you start a new test workbook and populate a bunch of cells with dummy data, then save it as a .CSV file. Then close excel. And open that .csv file in NotePad to see what it looks like. There are lots of programs that don't tal...

Transferring Text
I need to be able to send data from one worksheet to another. Sheet 1 is the master and only sheet where data is entered. I have found out all cells have to be set to "Text" - which is not a problem. Sheet 1 Column A is Name Column B is Date of Birth Column C is the Surgery's name Is there a way that when the Surgery name is entered in say C5 the row's Name and Date of Birth can be sent to the next vacant row in say Sheet 3. Because of the number of surgeries, it is not possible to set them up to receive data from Sheet 1 - which is much easier, of course. I thought o...

Calling on a macro within a macro!
Hey All!! Quick Question - How do you call up a macro within a current macro? I have one big macro and I need it to jump to several other macros when it runs! Does it matter where the other macros are stored or is it better to have them all in one module? Help appreciated Thnx! Hi Mellowe, '=============>> Public Sub Main() 'Your code Call One 'your code End Sub '<<============= '=============>> Public Sub One() MsgBox "Hi from One" End Sub '<<============= > Does it matter where the other macros are stored or ...

delete folder from personal folders
i have accidentally deleted a folder from my personal folder and when i restore the pst file i cannot find it! any ideas? ...

Trend Line constants as Excel Cell Values
I want to put the constants of a 2 degree polynomial trend line into Excel Cells. Are there formula's to do this? Equation is Y = Ax(2) + Bx + C. I want the value of A,B and C in seperate cells. Can anyone suggest how this can be done? Thanks -- Ken Hi Ken, Supposing your x-range is in A2:A10, and y-range in B2:B10, select a 3-column x 1-row area and enter the following formula and confirm with CTRL-SHIFT-ENTER. =LINEST(B2:B10,A2:A10^{0,1,2},0,) Regards, B. R. Ramachandran "Ken" wrote: > I want to put the constants of a 2 degree polynomial trend line into Excel &g...

shortcut keys to macros
Hi, Is it at all possible to assign shortcut keys to macros in Outlook? Thx, Hans ...

Converting TOC to Text
I cut and paste text from a table of contents into a Word 2003 document. It is very lengthy and I'd rather not re-type the whole long list, since it would take a very long time. However, the TOC formatting is still in the document and I can't get rid of it. I can't include hyperlinks or change font color as a result. I've tried clearing all formatting without effect. Anyone know how to convert a TOC into text? Thanks! Ctrl+Shift+F9 will unlink it. -- Suzanne S. Barnhill Microsoft MVP (Word) Words into Type Fairhope, Alabama USA http://word.mvps.org &q...

help Unable to record Macro !!!!!!!
I want to record a macro in excel.But as soon as I click record Macro it says "unable to record" macro. Got no help in excel help.I do this same thing in word and it's working. Please help It's urgent for me !!!1 Have a look here http://groups.google.com/groups?as_epq=unable%20to%20record&as_ugroup=microsoft.public.excel.* -- Don Guillett SalesAid Software donaldb@281.com "ash" <anonymous@discussions.microsoft.com> wrote in message news:3e0b01c42ae5$45333e00$a401280a@phx.gbl... > I want to record a macro in excel.But as soon as I click > record...

Data Text to Columns
I have a large column and would like to split it for the literal that says "Company Name" and then have the company name right next to it which is enterable. I tried using Data/Text to Columns, Fixed Width, sliding the arrow after Company Name: and it did not seem to split the column. I also tried putting an arrow out a ways so that there looked as though there were two defined fields and that didn't seem to work either. Am I approaching this the right way??? HELP!!! Thanks! Hi this is not possible in Excel. You have to use two columns for this -- Regards Frank Kabel Fr...

Chart Label wraps on the same line. "Wavelenght [nm]" appears as.
Chart Label wraps on the same line. example "Wavelenght [nm]" appears as "}Wavelenght [nm" in general the chart labels are not what i typed. Send me a copy of the file (personal mail not to newsgroup) What version of Excel are you using? -- Bernard Liengme www.stfx.ca/people/bliengme remove CAPS in email address "rog" <rog@discussions.microsoft.com> wrote in message news:E9369578-AA4B-480B-93A2-14D91B8AC1F8@microsoft.com... > Chart Label wraps on the same line. example "Wavelenght [nm]" appears as > "}Wavelenght [nm" >...