+ Reply to Thread
Results 1 to 11 of 11

Select and Delete Multiple Rows based on Cell contents

  1. #1
    Registered User
    Join Date
    01-28-2015
    Location
    Peoria, Illinois
    MS-Off Ver
    2013
    Posts
    23

    Select and Delete Multiple Rows based on Cell contents

    The situation:

    I have a number of .csv files in a specific folder. Let's say 10 files and I want to be able to open each file and look at the range of column "B"
    If any cell after B3 within the range, EG. B7, B9 or B100 etc. does NOT = "Smash" then I want the entire row selected and deleted.
    I don't want the data in that row to just be cleared, I want the row itself deleted.
    Once all rows are checked and deleted, then the file will SAVE and go to the next .csv file.

    PROGRESS:

    I have the code to open all of the files and then save them once an operation has been performed.

    WHAT I NEED ASSISTANCE WITH:
    I need the code to look at each cell within the range and then select and delete the rows that do not = "Smash"
    I have attached my current code that opens and saves along with the loop of previous code that performed a function and iterated through files. I know right where the new code should go and appreciate any help with the issue.
    I have also attached an example spreadsheet with the code in a module.
    In the spreadsheet example is Module 1, which has my original code that would open all .csv files in a folder and replace text in specific cells GI3, GJ3 and GK3 with "Percent."
    I also have Module 2 that is the same code, but has the sections '........................ of where new code should go.
    I have also attached example code.
    Thanks in advance for the help!

    Troy

    Please Login or Register  to view this content.
    Attached Files Attached Files

  2. #2
    Forum Guru
    Join Date
    09-10-2017
    Location
    Chippenham, England
    MS-Off Ver
    365
    Posts
    15,080

    Re: Select and Delete Multiple Rows based on Cell contents

    How about
    Please Login or Register  to view this content.

  3. #3
    Registered User
    Join Date
    01-28-2015
    Location
    Peoria, Illinois
    MS-Off Ver
    2013
    Posts
    23

    Re: Select and Delete Multiple Rows based on Cell contents

    Thanks Fluff13. When I add your code and run the macro the output results in the below:

    Fluff13_result.png

    I'm not sure why all row cells are copied into the first column.

    Here is how the output should look:

    Result_Ideal.png

    So close
    Last edited by Vanth_2013; 03-13-2018 at 08:41 AM.

  4. #4
    Forum Guru
    Join Date
    09-10-2017
    Location
    Chippenham, England
    MS-Off Ver
    365
    Posts
    15,080

    Re: Select and Delete Multiple Rows based on Cell contents

    Could you post your enitre code? as that should not be happening.

  5. #5
    Registered User
    Join Date
    01-28-2015
    Location
    Peoria, Illinois
    MS-Off Ver
    2013
    Posts
    23

    Re: Select and Delete Multiple Rows based on Cell contents

    Thanks for the help.

    Please Login or Register  to view this content.

  6. #6
    Forum Guru
    Join Date
    09-10-2017
    Location
    Chippenham, England
    MS-Off Ver
    365
    Posts
    15,080

    Re: Select and Delete Multiple Rows based on Cell contents

    That works for me, although this line
    Please Login or Register  to view this content.
    should probably be within the loop.
    Can you upload one of the csv files that is causing problems?

  7. #7
    Registered User
    Join Date
    01-28-2015
    Location
    Peoria, Illinois
    MS-Off Ver
    2013
    Posts
    23

    Re: Select and Delete Multiple Rows based on Cell contents

    I have the code working. Thanks for your help Fluff13!

    Here is the final code:

    Please Login or Register  to view this content.

  8. #8
    Forum Guru
    Join Date
    09-10-2017
    Location
    Chippenham, England
    MS-Off Ver
    365
    Posts
    15,080

    Re: Select and Delete Multiple Rows based on Cell contents

    Glad you got it sorted & thanks for the feedback

  9. #9
    Registered User
    Join Date
    01-28-2015
    Location
    Peoria, Illinois
    MS-Off Ver
    2013
    Posts
    23

    Re: Select and Delete Multiple Rows based on Cell contents

    First off. Thanks!

    The code works fast. I did have an issue that we overcame and I tell you this just as an FYI.

    Though I used "Smash" as my word to compare, in reality the strings I am using are different. E.G. F2R3 or R3F4 and other combinations.
    I initially used F2R3 and the macro worked perfectly on all of the files.
    Next, I tried R3F4 and the macro kept erroring out.
    What we found was, for some reason, excel does not like the first character to be an "R" followed by a single digit number.
    Our solution is to use "fR3F4" and the code works perfectly again, as it ignores the extra character in our solution.
    Just thought I would let you know of the weird occurrence.

    Here's the new code:

    Please Login or Register  to view this content.
    Additionally, we refined the code more, so I only needed to change one string for my changes!

    Please Login or Register  to view this content.

  10. #10
    Forum Guru
    Join Date
    09-10-2017
    Location
    Chippenham, England
    MS-Off Ver
    365
    Posts
    15,080

    Re: Select and Delete Multiple Rows based on Cell contents

    Many thanks for the feedback.

    The reason you had problems with R3F4, is that when you put an = sign in front xl thinks you are using an R1C1 reference.
    But as =R3F4 is not a valid reference it causes problems.

    Will you be doing multiple replaces on each file?

  11. #11
    Registered User
    Join Date
    01-28-2015
    Location
    Peoria, Illinois
    MS-Off Ver
    2013
    Posts
    23

    Re: Select and Delete Multiple Rows based on Cell contents

    It's my pleasure and thanks again for your help. The above helps explain the issue.

    No, I am only deleting rows that do NOT have the string R3F4, or whatever else I require, in Column "B" for each group of files.

    The code is exactly what I need for my current project.
    This will allow me to process all 1,085 files in two or 3 days rather than two weeks manually cleaning them out. An amount of cross referencing is also done, so I cannot say it's a fully automatic process.
    Last edited by Vanth_2013; 03-13-2018 at 02:37 PM.

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. Delete Rows Based On Cell Contents
    By aapke in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 08-28-2007, 08:14 PM
  2. [SOLVED] How do I conditionally delete rows based on cell contents?
    By CLR in forum Excel Formulas & Functions
    Replies: 4
    Last Post: 09-06-2005, 06:05 AM
  3. [SOLVED] How do I conditionally delete rows based on cell contents?
    By CLR in forum Excel Formulas & Functions
    Replies: 6
    Last Post: 09-06-2005, 04:05 AM
  4. How do I conditionally delete rows based on cell contents?
    By John Chan in forum Excel Formulas & Functions
    Replies: 0
    Last Post: 09-06-2005, 03:05 AM
  5. How do I conditionally delete rows based on cell contents?
    By John Chan in forum Excel Formulas & Functions
    Replies: 0
    Last Post: 09-06-2005, 12:05 AM
  6. [SOLVED] How do I conditionally delete rows based on cell contents?
    By John Chan in forum Excel Formulas & Functions
    Replies: 0
    Last Post: 09-05-2005, 11:05 PM
  7. [SOLVED] How do I conditionally delete rows based on cell contents?
    By John Chan in forum Excel Formulas & Functions
    Replies: 0
    Last Post: 09-05-2005, 10:05 PM
  8. How do I conditionally delete rows based on cell contents?
    By John Chan in forum Excel Formulas & Functions
    Replies: 2
    Last Post: 06-13-2005, 06:05 PM

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