+ Reply to Thread
Results 1 to 16 of 16

improve loop

  1. #1
    Registered User
    Join Date
    06-05-2019
    Location
    texas
    MS-Off Ver
    2013
    Posts
    53

    improve loop

    hello guys-I am trying to make this loop run a certain way. I have posted it. any help is appreciated.

    Please Login or Register  to view this content.

  2. #2
    Forum Expert
    Join Date
    12-14-2012
    Location
    London England
    MS-Off Ver
    MS 365 Office Suite.
    Posts
    8,448

    Re: improve loop

    The best way to improve your loop is to get rid of it.

    In Pseudocode:

    Copy all your data to sheet2

    Insert a formula in an Empty column to to return a 1 if column A <> Name

    Copy Paste Values

    Use select Special to select all the 1's in our helper column.

    Resize the selection to Delete all your flagged Rows

    There is no loop so this should be fast.

    Please Login or Register  to view this content.
    Attached Files Attached Files
    Last edited by mehmetcik; 04-14-2020 at 04:52 PM.
    My General Rules if you want my help. Not aimed at any person in particular:

    1. Please Make Requests not demands, none of us get paid here.

    2. Check back on your post regularly. I will not return to a post after 4 days.
    If it is not important to you then it definitely is not important to me.

  3. #3
    Forum Guru Kaper's Avatar
    Join Date
    12-14-2013
    Location
    Warsaw, Poland
    MS-Off Ver
    most often: Office 365 in Windows environment
    Posts
    8,864

    Re: improve loop

    Or test such code:
    Please Login or Register  to view this content.
    Best Regards,

    Kaper

  4. #4
    Registered User
    Join Date
    06-05-2019
    Location
    texas
    MS-Off Ver
    2013
    Posts
    53

    Re: improve loop

    EDIT: I have added a sample of attachment of what I am attempting to accomplish

    hello kaper- I am testing your suggested code. It is not looping to the next record in this section:

    Please Login or Register  to view this content.
    Attached Files Attached Files
    Last edited by hgchas; 04-15-2020 at 03:58 PM.

  5. #5
    Forum Guru Kaper's Avatar
    Join Date
    12-14-2013
    Location
    Warsaw, Poland
    MS-Off Ver
    most often: Office 365 in Windows environment
    Posts
    8,864

    Re: improve loop

    have you seen the yellow banner at the top of the page? Please follow the advice

  6. #6
    Registered User
    Join Date
    06-05-2019
    Location
    texas
    MS-Off Ver
    2013
    Posts
    53

    Re: improve loop

    hi-I have edited the previous reply with a sample attachment.

  7. #7
    Forum Expert
    Join Date
    11-24-2013
    Location
    Paris, France
    MS-Off Ver
    Excel 2003 / 2010
    Posts
    9,831

    Cool Hi ! Try this !


    According to post #4 attachment a VBA beginner starter demonstration :

    PHP Code: 
    Sub Demo1()
        
    Sheet2.UsedRange.Columns(1).Copy Sheet2.[K1]
        
    Sheet1.[C1:D1].Copy Sheet2.[C1]
        
    Sheet1.UsedRange.AdvancedFilter xlFilterCopySheet2.[K1].CurrentRegionSheet2.[A1:D1]
        
    Sheet2.[K1].CurrentRegion.Clear
    End Sub 

    The same demonstration revamped :

    PHP Code: 
    Sub Demo1r()
        
    With Sheet2.UsedRange.Columns
            
    .Item(1).Copy .Item(11)
             
    Sheet1.[C1:D1].Copy .Range("C1")
             
    Sheet1.UsedRange.AdvancedFilter xlFilterCopy, .Item(11), .Range("A1:D1")
            .
    Item(11).Clear
        End With
    End Sub 
    ► Do you like it ? ► ► So thanks to click on bottom left star icon « Add Reputation » ! ◄ ◄
    Last edited by Marc L; 04-15-2020 at 11:33 PM.

  8. #8
    Registered User
    Join Date
    06-05-2019
    Location
    texas
    MS-Off Ver
    2013
    Posts
    53

    Re: Hi ! Try this !

    Hi Marc-thank you for your feedback! I ran the code but I am looking to run a index/match function through each row between two datasets. The first post code worked but only returned one row and I am wanting to loop through the datasets to find commonalities

  9. #9
    Forum Guru Kaper's Avatar
    Join Date
    12-14-2013
    Location
    Warsaw, Poland
    MS-Off Ver
    most often: Office 365 in Windows environment
    Posts
    8,864

    Re: improve loop

    The example you posted in post #4 is quite different than what has been posted in post #1
    Moreover, I suspect that example data is oversimplified (see below for the attachment suggestions), because for such data with unique ID, a simple VLOOKUP would do the job.
    Use in C2 in sheet 2:
    Formula: copy to clipboard
    Please Login or Register  to view this content.
    and the same in D2, but with 4 (instead of 3) as third argument.

    ---
    1. Make sure that your sample data are truly REPRESENTATIVE of your real data. (If there are typical cases like: all unique values/duplicates could occur, day/night, nobody present/several persons at once, before/on/past due, empty cells between data, mixed text/numbers, etc. - please show them all, or at least indicate in text). The use of unrepresentative data is very frustrating and can lead to long delays in reaching a solution.

    2. Make sure that your desired solution(s) is/are also shown (mock up the results manually).

    3. Make sure that all confidential/restricted information (either personal or business) like real e-mails, social security numbers, bank accounts, etc. is removed first!!

  10. #10
    Forum Expert
    Join Date
    11-24-2013
    Location
    Paris, France
    MS-Off Ver
    Excel 2003 / 2010
    Posts
    9,831

    Arrow Re: Hi ! Try this !


    Quote Originally Posted by hgchas View Post
    Hi Marc-thank you for your feedback! I ran the code but I am looking to run a index/match function through each row between two datasets. The first post code worked but only returned one row and I am wanting to loop through the datasets to find commonalities
    The more data, the less efficient than using an advanced filter …

  11. #11
    Forum Expert
    Join Date
    11-24-2013
    Location
    Paris, France
    MS-Off Ver
    Excel 2003 / 2010
    Posts
    9,831

    Arrow Re: improve loop


    On my side my codes well work, return all the expected data according to your post #4 attachment …

  12. #12
    Registered User
    Join Date
    06-05-2019
    Location
    texas
    MS-Off Ver
    2013
    Posts
    53

    Re: improve loop

    hi-I have attached a workbook with sample data. I used the index/match function to show what I am wanting to accomplish. thanks in advance!
    Attached Files Attached Files

  13. #13
    Forum Expert
    Join Date
    11-24-2013
    Location
    Paris, France
    MS-Off Ver
    Excel 2003 / 2010
    Posts
    9,831

    Arrow Re: improve loop


    That's very weird to attach a sample with a different layout than the original (post #4)
    or you must be very confident with your Excel / VBA skills to amend any code !

    According to the last attachment, explain the actual layout of Sheet2,
    as there is no formula what exactly to do, attach the expected result, it may help, a lot …

  14. #14
    Registered User
    Join Date
    06-05-2019
    Location
    texas
    MS-Off Ver
    2013
    Posts
    53

    Re: improve loop

    hi marc-thanks for the feedback, I appreciate it! I have attached a different working sample with more data to reflect what I am wanting to accomplish. I hope I can convey what I am trying to do.
    Attached Files Attached Files

  15. #15
    Forum Guru xladept's Avatar
    Join Date
    04-14-2012
    Location
    Pasadena, California
    MS-Off Ver
    Excel 2003,2010
    Posts
    12,378

    Re: improve loop

    This works when the keys are properly entered - In your sample there were 3 East 95's for instance.

    But try it and see whether it works for you:

    Please Login or Register  to view this content.
    Last edited by xladept; 04-18-2020 at 12:05 AM.
    If I've helped you, please consider adding to my reputation - just click on the liitle star at the left.

    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~(Pride has no aftertaste.)

    You can't do one thing. XLAdept

    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~aka Orrin

  16. #16
    Forum Expert
    Join Date
    11-24-2013
    Location
    Paris, France
    MS-Off Ver
    Excel 2003 / 2010
    Posts
    9,831

    Arrow Re: improve loop

    Quote Originally Posted by hgchas View Post
    I have attached a workbook with sample data. I used the index/match function to show what I am wanting to accomplish.
    Again no formula within the attachment neither a technical explanation so no logic to apply, a guess challenge, no thanks …

+ 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. [SOLVED] Improve Speed: VBA Code very slow due to changing cell values in for loop
    By Nick_G in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 01-29-2020, 03:25 PM
  2. Improve code so it doesn't loop through worksheets seperately?
    By carissa7 in forum Excel Programming / VBA / Macros
    Replies: 9
    Last Post: 01-18-2018, 04:52 AM
  3. How to improve my code ?
    By ozstrik3r69 in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 10-23-2017, 08:51 AM
  4. Does this code needs improvement?
    By amartinez988 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 01-25-2016, 09:21 AM
  5. [SOLVED] Copy dynamically changing column and Paste using VBA Loop (Loop within Loop)
    By nixon72 in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 02-12-2013, 12:46 PM
  6. Need your help to improve
    By baba4005 in forum Hello..Introduce yourself
    Replies: 1
    Last Post: 04-19-2012, 03:32 PM
  7. Help to improve macro
    By unni5959 in forum Excel Programming / VBA / Macros
    Replies: 9
    Last Post: 09-19-2005, 07: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