+ Reply to Thread
Results 1 to 11 of 11

VBA for deleting cells containing specific text

  1. #1
    Registered User
    Join Date
    02-02-2013
    Location
    London
    MS-Off Ver
    Excel 2010
    Posts
    46

    VBA for deleting cells containing specific text

    Hi guys,

    I was wondering if anybody can give me help me with my question:

    I have a very big spreadsheet which I need to clean. I need to delete two types of cells, each containing different text. Let's suppose the first type contains "fits machines:" . I need to have a VBA script which will delete all the cells containing this combination of words, and shift the cell up in each deleted place.

    I can do that manually by the following method:

    1. Click on Ctrl+F, type there "fits machines:" , click on Find all.
    2. In the list found, click on Ctrl+A and select all the cells
    3. Click on delete cells
    4. From the option popped-up - choose to shift cell up

    However, the problem is my computer (icore3 processor) is performing the process very low. Assuming I have over 40000 records to do and seeing that it needs more than two hours to delete and shift up 5000 records, I can not wait that long for the entire process.

    I would appreciate your help very much, thank you.

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

    Re: VBA for deleting cells containing specific text

    Will this string be in one column or anywhere in the file?
    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]

  3. #3
    Registered User
    Join Date
    02-02-2013
    Location
    London
    MS-Off Ver
    Excel 2010
    Posts
    46

    Re: VBA for deleting cells containing specific text

    Hi Arlu,

    It is a file which contains over 1300 columns. Each column has about 30 cells with the text "fits machines:", so it's all over the document. I need the cells containing this text deleted and cells shift up. Do you have any suggestions?

  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: VBA for deleting cells containing specific text

    Try this code
    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

  5. #5
    Registered User
    Join Date
    03-25-2013
    Location
    UK
    MS-Off Ver
    Excel 2010
    Posts
    1

    Re: VBA for deleting cells containing specific text

    It's a thought, but it may be significantly faster to use a macro and add each cell containing the requisite text (i.e. "fits machine:") to a selection, then do something like Selection.Delete. Try recording a macro of the manual process to see what you can use from that to perform the cell deletion.

    This way it only has to rejig the workbook contents once, rather than for each instance of the search text.
    Last edited by Code&Chips; 03-25-2013 at 07:00 AM. Reason: more detail

  6. #6
    Registered User
    Join Date
    02-02-2013
    Location
    London
    MS-Off Ver
    Excel 2010
    Posts
    46

    Re: VBA for deleting cells containing specific text

    Arlu, thank you for your help. The code is perfect, but I assume it works only for cells which contain only the two words "fits machines:", however in my case there are other words after "fits machines:" and in each case it is different. That's why I mentioned that I need a code for cells containing "fits machines:" , but not only these two words. Can you tell me where to adjust the code please?

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

    Re: VBA for deleting cells containing specific text

    Change this line from
    Please Login or Register  to view this content.
    to
    Please Login or Register  to view this content.

  8. #8
    Valued Forum Contributor abduljaleel.mca's Avatar
    Join Date
    02-13-2013
    Location
    Chennai, India
    MS-Off Ver
    MS 365 Business
    Posts
    326

    Re: VBA for deleting cells containing specific text

    Use the below formula

    Please Login or Register  to view this content.

  9. #9
    Registered User
    Join Date
    02-02-2013
    Location
    London
    MS-Off Ver
    Excel 2010
    Posts
    46

    Re: VBA for deleting cells containing specific text

    Arlu, thank you, it worked well, but one thing - it stopped at column IA , and doesn't perform further. Can this be solved as well please?

  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: VBA for deleting cells containing specific text

    Regarding the columns, the macro checks the last column in each row and then proceeds. So it will check till the last column of row 2, then go to row 3. So it should work on all your columns.

  11. #11
    Registered User
    Join Date
    02-02-2013
    Location
    London
    MS-Off Ver
    Excel 2010
    Posts
    46

    Re: VBA for deleting cells containing specific text

    Arlu, something is indeed wrong and not working, I just tried with another similar document, can we exchange emails so that I can send you the document and you could see it yourself please?

  12. #12
    Registered User
    Join Date
    03-05-2013
    Location
    London
    MS-Off Ver
    Excel 2003
    Posts
    10

    Command button used to insert new row in alphabetical order

    I require a command button that will ask various questions such as 'client code' & 'client name'. I need this information to be produced in column a & b on a new row. I also need this row to be inserted alphabetically with all other rows and copy formulas that exist in other rows.

  13. #13
    Forum Expert
    Join Date
    03-28-2012
    Location
    TBA
    MS-Off Ver
    Office 365
    Posts
    12,454

    Re: Command button used to insert new row in alphabetical order

    Andrew,
    Try this one

    Please Login or Register  to view this content.

  14. #14
    Forum Expert
    Join Date
    03-28-2012
    Location
    TBA
    MS-Off Ver
    Office 365
    Posts
    12,454

    Re: Command button used to insert new row in alphabetical order

    Hobson,
    Please re-start your own thread. It is against forum's rule to post on someone else's post.

+ 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