+ Reply to Thread
Results 1 to 13 of 13

Delete rows that DO NOT contain criteria texts

  1. #1
    Registered User
    Join Date
    09-13-2012
    Location
    Bangalore
    MS-Off Ver
    Excel 2007
    Posts
    8

    Delete rows that DO NOT contain criteria texts

    Hi

    I am novice excel user and trying to search and found solution to my issue, I came close to it but not yet got what I wanted exactly. I am looking for a macro to delete rows that DO NOT contain criteria. But what I could achieve so far is deleting all rows except the first word ie ACC here. My code so far is as follows

    Please Login or Register  to view this content.
    I see some issue at code marked in red. Need help resolving this. Thanks, in advance
    Last edited by arlu1201; 12-15-2012 at 05:33 AM.

  2. #2
    Forum Guru :) Sixthsense :)'s Avatar
    Join Date
    01-01-2012
    Location
    India>Tamilnadu>Chennai
    MS-Off Ver
    2003 To 2010
    Posts
    12,770

    Re: Delete rows that DO NOT contain criteria texts

    I believe instead of mentioning the criteria's inside the code I suggest you to use a helper column in a separate worksheet and add all your criteria's and and use a loop on it.


    If your problem is solved, then please mark the thread as SOLVED>>Above your first post>>Thread Tools>>
    Mark your thread as Solved


    If the suggestion helps you, then Click *below to Add Reputation

  3. #3
    Forum Contributor arlu1201's Avatar
    Join Date
    09-09-2011
    Location
    Bangalore, India
    MS-Off Ver
    Excel 2003 & 2007
    Posts
    19,166

    Re: Delete rows that DO NOT contain criteria texts

    masterthetrade,

    Welcome to the forum.

    I have added code tags to your post. As per forum rule 3, you need to use them whenever you put any code in your post. Please add them in future. If you need more information on how to use them, check my signature below this post.
    If I have helped, Don't forget to add to my reputation (click on the star below the post)
    Don't forget to mark threads as "Solved" (Thread Tools->Mark thread as Solved)
    Use code tags when posting your VBA code: [code] Your code here [/code]

  4. #4
    Forum Contributor arlu1201's Avatar
    Join Date
    09-09-2011
    Location
    Bangalore, India
    MS-Off Ver
    Excel 2003 & 2007
    Posts
    19,166

    Re: Delete rows that DO NOT contain criteria texts

    You have 2 options -

    1. If the list of items to be deleted is huge, you can retain them in a column in your macro file and have the macro loop through each one.

    2. If the list of items to be retained is small, you can mention those in the macro and ask the macro to check only the retained ones, everything else to be deleted.

  5. #5
    Registered User
    Join Date
    09-13-2012
    Location
    Bangalore
    MS-Off Ver
    Excel 2007
    Posts
    8

    Re: Delete rows that DO NOT contain criteria texts

    Quote Originally Posted by arlu1201 View Post
    You have 2 options -

    1. If the list of items to be deleted is huge, you can retain them in a column in your macro file and have the macro loop through each one.

    2. If the list of items to be retained is small, you can mention those in the macro and ask the macro to check only the retained ones, everything else to be deleted.
    Hi Arlu 1201

    Thankyou. Rows to be deleted are about 1500 and rows to be retained are 50 that contain words I mentioned in the code I posted. Is it possible to modify the code I posted and re-post the modified code here? As I mentioned earlier, I am novice to VB and do not know much of it. I searched the forum and found the above code and slightly modified with little knowledge I have but it is not enough to resolve the issue! Thank you. Please note the 50 words I mentioned are pertaining to 50 rows in column A, they are not duplicated in any other row or column.
    Last edited by masterthetrade; 12-15-2012 at 11:45 AM.

  6. #6
    Forum Contributor arlu1201's Avatar
    Join Date
    09-09-2011
    Location
    Bangalore, India
    MS-Off Ver
    Excel 2003 & 2007
    Posts
    19,166

    Re: Delete rows that DO NOT contain criteria texts

    Try this code - Sheet1 contains the entire data in column A, Sheet2 contains the list of items to be deleted in column A.
    Please Login or Register  to view this content.
    Copy the Excel VBA code
    Select the workbook in which you want to store the Excel VBA code
    Hold the Alt key, and press the F11 key, to open the Visual Basic Editor
    Choose Insert | Module
    Where the cursor is flashing, choose Edit | Paste

    To run the Excel VBA code:
    Choose View | Macros
    Select a macro in the list, and click the Run button

  7. #7
    Registered User
    Join Date
    09-13-2012
    Location
    Bangalore
    MS-Off Ver
    Excel 2007
    Posts
    8

    Re: Delete rows that DO NOT contain criteria texts

    Hi Arlu1201

    This has done the trick for me, thank you very much

    One more small request, in continuation to above. After deleting rows using the above code, if I wanted to few more columns also to be deleted, which have headers as SERIES, ISIN and LAST; how do I do that? If you do not mind can you please paste the complete consolidated code?

    Thank you.
    Last edited by arlu1201; 12-16-2012 at 09:21 AM. Reason: Do not quote whole posts.

  8. #8
    Forum Contributor arlu1201's Avatar
    Join Date
    09-09-2011
    Location
    Bangalore, India
    MS-Off Ver
    Excel 2003 & 2007
    Posts
    19,166

    Re: Delete rows that DO NOT contain criteria texts

    Are these columns in specific locations every time you get the data? For e.g. if SERIES is in column A, will it always be column A?

    Are these the only 3 columns to be deleted?

  9. #9
    Registered User
    Join Date
    09-13-2012
    Location
    Bangalore
    MS-Off Ver
    Excel 2007
    Posts
    8

    Re: Delete rows that DO NOT contain criteria texts

    Quote Originally Posted by arlu1201 View Post
    Are these columns in specific locations every time you get the data? For e.g. if SERIES is in column A, will it always be column A?

    Are these the only 3 columns to be deleted?
    Apart from the rows mentioned in the previous code the following columns have to be deleted. The rows and columns to be deleted are almost the same every day.

    SERIES (Column B), LAST (Column G), PREVCLOSE (Column H), TOTTRDQTY (Columns I), TOTTRDVAL (Column J), TOTALTRADES (Column L), ISIN (Column M) are to be deleted. Column headers remain the same every day, only cell values change.

    Thank you.

  10. #10
    Forum Contributor arlu1201's Avatar
    Join Date
    09-09-2011
    Location
    Bangalore, India
    MS-Off Ver
    Excel 2003 & 2007
    Posts
    19,166

    Re: Delete rows that DO NOT contain criteria texts

    Updated code -
    Please Login or Register  to view this content.

  11. #11
    Registered User
    Join Date
    09-13-2012
    Location
    Bangalore
    MS-Off Ver
    Excel 2007
    Posts
    8

    Re: Delete rows that DO NOT contain criteria texts

    Hi Arlette

    I tried the above code but it is deleting column K but not deleting Columns L & M. ie deleting Column B and Columns G:K but not deleting Columns L & M

  12. #12
    Forum Contributor arlu1201's Avatar
    Join Date
    09-09-2011
    Location
    Bangalore, India
    MS-Off Ver
    Excel 2003 & 2007
    Posts
    19,166

    Re: Delete rows that DO NOT contain criteria texts

    Oops actually these are delete codes, hence you will need to reverse it.

    Updated code -
    Please Login or Register  to view this content.

  13. #13
    Registered User
    Join Date
    09-13-2012
    Location
    Bangalore
    MS-Off Ver
    Excel 2007
    Posts
    8

    Re: Delete rows that DO NOT contain criteria texts

    yaaahoo...! This works fine, Thank you.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1