+ Reply to Thread
Results 1 to 7 of 7

Loop too slow

  1. #1
    Registered User
    Join Date
    01-03-2018
    Location
    Ohio
    MS-Off Ver
    2016
    Posts
    28

    Loop too slow

    Hello. I have a loop checking to see if a given cell in a specified column begins with a semicolon or a blank space. Some of the cells begin with 0 or 1 semicolons or spaces and some of them begin with multiple. It works and does exactly what I need it to. It is just too slow because I am dealing with good sized files. Is there a faster way to do this? Code is below. Thank you.


    /begin code


    Range("R2").Select
    Dim myString As String
    myString = Selection.Cells.Value

    Do While IsEmpty(Selection.Cells.Value) = False
    Do While Left(myString, 1) = ";" Or Left(myString, 1) = " "
    Selection.Cells.Value = Right(myString, Len(myString) - 1)
    myString = Selection.Cells.Value
    Loop

    ActiveCell.Offset(1).Select
    myString = Selection.Cells.Value
    Loop


    / end code

  2. #2
    Forum Expert Mumps1's Avatar
    Join Date
    10-10-2012
    Location
    Toronto, Canada
    MS-Off Ver
    Excel 2010, 2013
    Posts
    7,844

    Re: Loop too slow

    It would be easier to help and test possible solutions if you could attach a copy of your file. Explain in detail what you want to do referring to specific cells, rows, columns and sheets using a few examples from your data (de-sensitized if necessary). See the yellow banner at the top of this page for instructions to attach a file.
    You can say "THANK YOU" for help received by clicking the Star symbol at the bottom left of the helper's post.
    Practice makes perfect. I'm very far from perfect so I'm still practising.

  3. #3
    Registered User
    Join Date
    01-03-2018
    Location
    Ohio
    MS-Off Ver
    2016
    Posts
    28

    Re: Loop too slow

    I have attached a small sample. If the cell begins with anything other than words, I want all the leading characters removed until the cell starts with words. As long as the cell begins with words, semicolons and or spaces can exist in the rest of the cell. They just can't be first in the cell. If the cell just has spaces or semicolons in it and no words, I want the entire cell blanked out. It is working fine now. It is just too slow.
    Attached Files Attached Files

  4. #4
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    44,638

    Re: Loop too slow

    Don't select the cells, or offset.

    Use:

    Please Login or Register  to view this content.
    Trevor Shuttleworth - Retired Excel/VBA Consultant

    I dream of a better world where chickens can cross the road without having their motives questioned

    'Being unapologetic means never having to say you're sorry' John Cooper Clarke


  5. #5
    Forum Expert Mumps1's Avatar
    Join Date
    10-10-2012
    Location
    Toronto, Canada
    MS-Off Ver
    Excel 2010, 2013
    Posts
    7,844

    Re: Loop too slow

    Try:
    Please Login or Register  to view this content.

  6. #6
    Registered User
    Join Date
    01-03-2018
    Location
    Ohio
    MS-Off Ver
    2016
    Posts
    28

    Re: Loop too slow

    Mumps1- Works great. Thanks!!

  7. #7
    Forum Expert Mumps1's Avatar
    Join Date
    10-10-2012
    Location
    Toronto, Canada
    MS-Off Ver
    Excel 2010, 2013
    Posts
    7,844

    Re: Loop too slow

    You are very welcome.

+ 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. Do while loop very slow?
    By Bundi999 in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 06-11-2018, 05:24 AM
  2. Loop running very slow
    By [email protected] in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 12-16-2017, 04:42 PM
  3. slow vba loop with arrays
    By danmcdon in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 08-16-2012, 10:55 PM
  4. For each loop very slow
    By CassioGodinho in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 04-02-2012, 04:50 PM
  5. Slow Do While Loop
    By bd528 in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 09-10-2010, 02:22 PM
  6. How do I slow down my loop ?
    By svanni in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 11-06-2006, 06:48 PM
  7. EXCEPTIONALLY SLOW LOOP ....help!!!
    By WhytheQ in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 06-13-2006, 01:10 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