+ Reply to Thread
Results 1 to 7 of 7

how to avoid using loop in this case

  1. #1
    Forum Contributor
    Join Date
    11-12-2010
    Location
    HK
    MS-Off Ver
    Excel 2010
    Posts
    189

    how to avoid using loop in this case

    Hi all,

    I am wondering if there are any ways out to do the following task instead of using loop to search each cell. This is a bit slow. Thanks
    An sample file is attached.
    sample.xls
    Please Login or Register  to view this content.
    English is not my first language

  2. #2
    Forum Moderator zbor's Avatar
    Join Date
    02-10-2009
    Location
    Croatia
    MS-Off Ver
    365 ProPlus
    Posts
    15,602

    Re: how to avoid using loop in this case

    Here:

    Please Login or Register  to view this content.
    Just instead .Select of the range define that range as you want.

  3. #3
    Forum Expert nilem's Avatar
    Join Date
    10-22-2011
    Location
    Ufa, Russia
    MS-Off Ver
    2013
    Posts
    3,377

    Re: how to avoid using loop in this case

    an option
    Please Login or Register  to view this content.

  4. #4
    Forum Contributor
    Join Date
    11-12-2010
    Location
    HK
    MS-Off Ver
    Excel 2010
    Posts
    189

    Re: how to avoid using loop in this case

    Quote Originally Posted by nilem View Post
    an option
    Please Login or Register  to view this content.
    thanks nilem, this is what i am looking for.

  5. #5
    Forum Contributor
    Join Date
    05-27-2014
    Location
    Belfast, Northern Ireland
    MS-Off Ver
    2007 & 2010
    Posts
    273

    Re: how to avoid using loop in this case

    Quote Originally Posted by nilem View Post
    an option
    Please Login or Register  to view this content.
    Quote Originally Posted by zbor View Post
    Here:

    Please Login or Register  to view this content.
    Just instead .Select of the range define that range as you want.
    OP's original code checks the selected data and, based on the results there, clears the contents of positionally related cells in another sheet ("temp chart"). It searches through the selected data starting with the last column and moves in reverse direction (to the left) along the columns after each loop. The first column it reaches that does not meet the criteria, exits the loop.

    So it could be the intended design of the procedure that only cells on the other sheet to the right of that column are cleared leaving all columns up to that column unaffected regardless of contents. Also, columns 1 to 9 of the selection are not even included in the loop so are never changed.

    Your codes both remove data from the source data instead of from another sheet and they affect all of the data not just some of it.

    That said, I'm having trouble coming up with a quicker way than this. I had thought about using ".cells.find" somehow until I saw the pattern of data removal.

    Can OP clarify what the expected end result is or even provide a current working example?
    Please click *Add Reputation if I've helped

  6. #6
    Forum Contributor
    Join Date
    11-12-2010
    Location
    HK
    MS-Off Ver
    Excel 2010
    Posts
    189

    Re: how to avoid using loop in this case

    Quote Originally Posted by kadeo View Post
    OP's original code checks the selected data and, based on the results there, clears the contents of positionally related cells in another sheet ("temp chart"). It searches through the selected data starting with the last column and moves in reverse direction (to the left) along the columns after each loop. The first column it reaches that does not meet the criteria, exits the loop.

    So it could be the intended design of the procedure that only cells on the other sheet to the right of that column are cleared leaving all columns up to that column unaffected regardless of contents. Also, columns 1 to 9 of the selection are not even included in the loop so are never changed.

    Your codes both remove data from the source data instead of from another sheet and they affect all of the data not just some of it.

    That said, I'm having trouble coming up with a quicker way than this. I had thought about using ".cells.find" somehow until I saw the pattern of data removal.

    Can OP clarify what the expected end result is or even provide a current working example?
    kadeo, you are right, I just found an issue on the solution.

    First of all, I am sorry to say all the data happened on the same sheet, so the sheets("temp chart") is also the sheet carrying the original data.
    Second, I intend to do the check for all columns in the selection, not to exclude column 1 to 9.
    Please see the updated code below

    Please Login or Register  to view this content.
    For nilem's solution, it deleted all the columns in the selection if they contain one "#N/A", but my intention is to delete the columns if both upper and lower cell contain "#N/A". Thus, this is not perfectly solve my issue. Is there anyone getting alternative solution? Thanks in advance

  7. #7
    Forum Expert nilem's Avatar
    Join Date
    10-22-2011
    Location
    Ufa, Russia
    MS-Off Ver
    2013
    Posts
    3,377

    Re: how to avoid using loop in this case

    maybe so
    Please Login or Register  to view this content.

+ 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. How to Avoid Infinite Loop?
    By BYizz in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 08-31-2013, 11:51 PM
  2. Select Case in a loop something like this possible?
    By scottr99 in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 03-29-2012, 05:31 PM
  3. Repeated action. Is it possible to avoid loop ?
    By Jasutasu in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 01-18-2011, 01:44 PM
  4. How can I avoid changing a loop counter within a loop?
    By broro183 in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 10-26-2009, 07:59 PM
  5. A better Case (was "Create Loop with Case statement")
    By Rick_Stanich in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 09-16-2009, 12:55 PM
  6. Can arrays be identified by i = X TO Y statements? (Avoid select Case)
    By macyarab in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 02-18-2009, 08:21 AM
  7. Avoid using .activate during loop
    By Rhapsodie in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 11-06-2008, 05:12 PM
  8. Can I use a Loop in this case?
    By papastyle3 in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 04-04-2008, 02:12 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