+ Reply to Thread
Results 1 to 4 of 4

Do I use a loop? If so, which one do I use?

  1. #1
    Forum Contributor
    Join Date
    12-19-2012
    Location
    Woodbridge, Virginia
    MS-Off Ver
    Excel 2010
    Posts
    111

    Do I use a loop? If so, which one do I use?

    All,

    I am trying to find a more efficient and smart way to load values from a database to my userform when it initializes. I am currently using a For loop. Here is my code below:

    Please Login or Register  to view this content.
    How can I make this more efficient? The problem is the user might only have 3 rows of data (ID2, ID3, and ID4) but this for loop goes through all 7 rows of data to see if the If condition is true or not. I am not very good with VBA or programming as you can tell by my code. Please let me know if there are other ways of doing this.

    Thank you for your help.

    J

  2. #2
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,258

    Re: Do I use a loop? If so, which one do I use?

    Hello s2jrchoi,

    ID2, ID3, and ID4 are not rows but cell data. You can not control what goes into to the cells which means you have to check each and every one for a possible match.
    Sincerely,
    Leith Ross

    Remember To Do the Following....

    1. Use code tags. Place [CODE] before the first line of code and [/CODE] after the last line of code.
    2. Thank those who have helped you by clicking the Star below the post.
    3. Please mark your post [SOLVED] if it has been answered satisfactorily.


    Old Scottish Proverb...
    Luathaid gu deanamh maille! (Rushing causes delays!)

  3. #3
    Forum Expert
    Join Date
    12-24-2007
    Location
    Alsace - France
    MS-Off Ver
    MS 365 Office Suite
    Posts
    5,066

    Re: Do I use a loop? If so, which one do I use?

    Perhaps not more efficient but different

    Please Login or Register  to view this content.
    - Battle without fear gives no glory - Just try

  4. #4
    Forum Contributor
    Join Date
    12-19-2012
    Location
    Woodbridge, Virginia
    MS-Off Ver
    Excel 2010
    Posts
    111

    Re: Do I use a loop? If so, which one do I use?

    Thank you Leith and Ross.

    Ross - Thank you so much for your input. I think that is the best approach. Will mark this as solved!

    J

+ 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] Find function in nested loop breaking down - not on first time through loop
    By adamstarr12 in forum Excel Programming / VBA / Macros
    Replies: 10
    Last Post: 10-14-2014, 09:32 AM
  2. HOW TO: Pause loop, fix error on a popup UserForm, continue loop
    By AndyMachin in forum Excel Programming / VBA / Macros
    Replies: 9
    Last Post: 06-19-2014, 04:37 PM
  3. [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
  4. Why did an inner loop variable start overwriting the outer loop range suddenly?
    By 111StepsAhead in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 05-16-2012, 03:24 PM
  5. Replies: 0
    Last Post: 07-20-2010, 11:42 AM

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