+ Reply to Thread
Results 1 to 24 of 24

Loop that Deletes Rows

  1. #1
    Forum Contributor
    Join Date
    07-15-2013
    Location
    New York, NY
    MS-Off Ver
    Excel 2010
    Posts
    129

    Loop that Deletes Rows

    Hi guys,

    I've tried executing this with normal excel functions, but it doesn't seem to work for me, so I'm hoping you all could help me out with a VBA code.

    The goal is the run a loop on the values in AL:AV in the attached workbook. I'd like the code to search for the first number it finds and then clear the next 10 "days" or rows, then stop the code after it has cleared 10 rows, and again start searching for the next number in that column. As you can see, numbers are sporatically distributed in each column, so I can't just continously run a loop--it needs to be more specific.

    Any ideas??
    Attached Files Attached Files

  2. #2
    Forum Expert Solus Rankin's Avatar
    Join Date
    05-24-2013
    Location
    Hollywood, CA
    MS-Off Ver
    Win7 Office 2010 VS Express 2012
    Posts
    2,655

    Re: Loop that Deletes Rows

    Are you adding 10 rows below the number you're searching for? Or clearing the contents from the current 10 rows below the number you're searching for?
    Thanks,
    Solus


    Please remember the following:

    1. Use [code] code tags [/code]. It keeps posts clean, easy-to-read, and maintains VBA formatting.
    Highlight the code in your post and press the # button in the toolbar.
    2. Show appreciation to those who have helped you by clicking below their posts.
    3. If you are happy with a solution to your problem, mark the thread as [SOLVED] using the tools at the top.

    "Slow is smooth, smooth is fast."

  3. #3
    Forum Contributor
    Join Date
    07-15-2013
    Location
    New York, NY
    MS-Off Ver
    Excel 2010
    Posts
    129

    Re: Loop that Deletes Rows

    I'm clearing the contents of the 10 rows below the searched for number.

  4. #4
    Forum Expert Solus Rankin's Avatar
    Join Date
    05-24-2013
    Location
    Hollywood, CA
    MS-Off Ver
    Win7 Office 2010 VS Express 2012
    Posts
    2,655

    Re: Loop that Deletes Rows

    so it is supposed to look for the number in AL1 and if it finds it, clear 10 rows, then go on to the number found in AL2? Looking in all columns? AL-AV?

  5. #5
    Forum Contributor
    Join Date
    07-15-2013
    Location
    New York, NY
    MS-Off Ver
    Excel 2010
    Posts
    129

    Re: Loop that Deletes Rows

    You got it

  6. #6
    Forum Expert Solus Rankin's Avatar
    Join Date
    05-24-2013
    Location
    Hollywood, CA
    MS-Off Ver
    Win7 Office 2010 VS Express 2012
    Posts
    2,655

    Re: Loop that Deletes Rows

    What if the number you're looking for in AL2 gets deleted when the number in AL1 is found? No problem?

  7. #7
    Forum Expert Solus Rankin's Avatar
    Join Date
    05-24-2013
    Location
    Hollywood, CA
    MS-Off Ver
    Win7 Office 2010 VS Express 2012
    Posts
    2,655

    Re: Loop that Deletes Rows

    Also, would you like the contents cleared from the original cell? or the one the value was found in?

  8. #8
    Forum Contributor
    Join Date
    07-15-2013
    Location
    New York, NY
    MS-Off Ver
    Excel 2010
    Posts
    129

    Re: Loop that Deletes Rows

    Hey

    So the "point" is for AL2 to get deleted if AL1 is found. If AL1 is found, then AL2-AL10 should be deleted. But ONLY if AL1 found.

    So for example, if you look at the sheet, the code should find that AL13 is populated with a number, and then clear AL14-AL23. Then stop the loop, and look for a number again. It should find a number in AL36, adn therefore clear AL37-AL46. WHen it runs the loop again, it will find a number in AL47, and do the same thing.

    In regards to your other question, I think you mean do I want the values in, for example, AL47 cleared or the value in the Calc! sheet where it originated? I only want the values in AL47.

  9. #9
    Forum Expert Solus Rankin's Avatar
    Join Date
    05-24-2013
    Location
    Hollywood, CA
    MS-Off Ver
    Win7 Office 2010 VS Express 2012
    Posts
    2,655

    Re: Loop that Deletes Rows

    Not exactly sure but try:
    Please Login or Register  to view this content.

  10. #10
    Forum Contributor
    Join Date
    07-15-2013
    Location
    New York, NY
    MS-Off Ver
    Excel 2010
    Posts
    129

    Re: Loop that Deletes Rows

    Thanks for the code. When I tried it, however, x = Round(Cells(l, i).Value, 3) had a mismatch

  11. #11
    Forum Expert Solus Rankin's Avatar
    Join Date
    05-24-2013
    Location
    Hollywood, CA
    MS-Off Ver
    Win7 Office 2010 VS Express 2012
    Posts
    2,655

    Re: Loop that Deletes Rows

    Do you have cells with words instead of numbers?

  12. #12
    Forum Contributor
    Join Date
    07-15-2013
    Location
    New York, NY
    MS-Off Ver
    Excel 2010
    Posts
    129

    Re: Loop that Deletes Rows

    I have "headers" in AL 1 and 2. But I changed Range("AL1").Select to Range("AL13").Select so I figured that wouldn't be an issue. Maybe not...

    Also, question, is this only applying to column AL? Becacuse the same idea should be applied to AL:AV, its just that the numbers are in different places so where the loop would stop and start will be different in each column

  13. #13
    Forum Expert Solus Rankin's Avatar
    Join Date
    05-24-2013
    Location
    Hollywood, CA
    MS-Off Ver
    Win7 Office 2010 VS Express 2012
    Posts
    2,655

    Re: Loop that Deletes Rows

    Yes it applies to all columns. Try:
    Please Login or Register  to view this content.

  14. #14
    Forum Contributor
    Join Date
    07-15-2013
    Location
    New York, NY
    MS-Off Ver
    Excel 2010
    Posts
    129

    Re: Loop that Deletes Rows

    Hmm so it was able to run. But it ran on the values from Z:AV, and also cleared some numbers but didn't clear others. Did you try the code on the workbook I sent you? If you do, take a look at AL36 for example. Because there is a number there, AL37-AL46 should be cleared.

  15. #15
    Forum Expert Solus Rankin's Avatar
    Join Date
    05-24-2013
    Location
    Hollywood, CA
    MS-Off Ver
    Win7 Office 2010 VS Express 2012
    Posts
    2,655

    Re: Loop that Deletes Rows

    It shouldn't have ran from Z. It ran on the proper columns in the workbook you attached.

    The rows below AL37 aren't cleared because the value for it doesn't appear anywhere else. I thought that was the stipulation you wanted?

  16. #16
    Forum Expert Solus Rankin's Avatar
    Join Date
    05-24-2013
    Location
    Hollywood, CA
    MS-Off Ver
    Win7 Office 2010 VS Express 2012
    Posts
    2,655

    Re: Loop that Deletes Rows

    See attached. Workbook after code is ran.Book21.xlsm

  17. #17
    Forum Contributor
    Join Date
    07-15-2013
    Location
    New York, NY
    MS-Off Ver
    Excel 2010
    Posts
    129

    Re: Loop that Deletes Rows

    Okay now it's working on the right range.

    These numbers are being taken from another sheet that is not attached to the workbook called "Calc!" I thought you were asking if I wanted the numbers on the Calc! sheet to also be cleared, which I do not. Could you clarify what you mean by "the value for it doesn't appear anywhere else"?

  18. #18
    Forum Expert Solus Rankin's Avatar
    Join Date
    05-24-2013
    Location
    Hollywood, CA
    MS-Off Ver
    Win7 Office 2010 VS Express 2012
    Posts
    2,655

    Re: Loop that Deletes Rows

    I thought you wanted to take the value of AL2, search the rest of the columns for that value. If it exists in other columns than clear contents AL3-AL12. Then take the next value (if AL3-12 were cleared it would be AL13, if not it would be AL3) then look for that new value in all the other columns. If it is found then clear the next 10 rows. So on and so forth until you've looked for all values in AL-AV

  19. #19
    Forum Contributor
    Join Date
    07-15-2013
    Location
    New York, NY
    MS-Off Ver
    Excel 2010
    Posts
    129

    Re: Loop that Deletes Rows

    Okay I see. Let me be more clear.

    It doesn't matter if the number exists anywhere else. It just matters if there's a number in that cell. "If AL1 is found, then AL2-AL10 should be deleted. But ONLY if AL1 found." I mean only if a number is found in AL1.

    So for example, if you look at the sheet, the code should find that AL13 is populated with a number, and then clear AL14-AL23. Then stop the loop, and look for a number (i.e. any number) again. It should find a number in AL36, adn therefore clear AL37-AL46. WHen it runs the loop again, it will find a number in AL47, and do the same thing. It just matters if the cell has a value in it and is not blank

  20. #20
    Forum Expert Solus Rankin's Avatar
    Join Date
    05-24-2013
    Location
    Hollywood, CA
    MS-Off Ver
    Win7 Office 2010 VS Express 2012
    Posts
    2,655

    Re: Loop that Deletes Rows

    Well thats much easier . Try:

    Please Login or Register  to view this content.

  21. #21
    Forum Contributor
    Join Date
    07-15-2013
    Location
    New York, NY
    MS-Off Ver
    Excel 2010
    Posts
    129

    Re: Loop that Deletes Rows

    That worked perfectly in the workbook I sent you!! Thank you!

    But when I try to use it in another workbook (with the ranges the same--AL:AV) it runs the code on Z:AV. Any idea why that happens?

  22. #22
    Forum Contributor
    Join Date
    07-15-2013
    Location
    New York, NY
    MS-Off Ver
    Excel 2010
    Posts
    129

    Re: Loop that Deletes Rows

    It's exactly the same format as the workbook I sent you, except there are headers which are text

  23. #23
    Forum Expert Solus Rankin's Avatar
    Join Date
    05-24-2013
    Location
    Hollywood, CA
    MS-Off Ver
    Win7 Office 2010 VS Express 2012
    Posts
    2,655

    Re: Loop that Deletes Rows

    No idea. Its set to run on columns 38 to 48 (Which should always be columns AL to AV even if you have hidden columns).


    e/ unless there are more letters in your alphabet

  24. #24
    Forum Contributor
    Join Date
    07-15-2013
    Location
    New York, NY
    MS-Off Ver
    Excel 2010
    Posts
    129

    Re: Loop that Deletes Rows

    Oh nevermind, we're good.

    Thanks so much for your help!!!

+ 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. Macro that deletes rows below a certain value
    By Biased Historian in forum Excel Programming / VBA / Macros
    Replies: 16
    Last Post: 01-15-2011, 09:45 PM
  2. Replies: 1
    Last Post: 12-15-2009, 02:17 PM
  3. Macro that Deletes All rows except first row
    By curtney in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 07-18-2006, 01:22 PM
  4. [SOLVED] Help With a Loop That Deletes Rows
    By Vecchia in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 11-21-2005, 06:10 PM
  5. [SOLVED] Loop that deletes sheets if data ends on a certain row
    By Please Help in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 02-03-2005, 01:06 PM

Tags for this Thread

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