+ Reply to Thread
Results 1 to 16 of 16

Do Loop error - first week with VBA

  1. #1
    Registered User
    Join Date
    06-12-2012
    Location
    Milwaukee
    MS-Off Ver
    Excel 2007/2010
    Posts
    18

    Do Loop error - first week with VBA

    Good morning everyone. I've only recently started getting into VBA in excel. I've taken a few VBA for Excel classes online so I understand the very basics. I have written a few codes with the help of a few google searches but this one has me stumped.

    I have a list of customers with time windows for when product can be delivered. For some reason, time windows read 0 rather than actual times for several customers. I'd like vba to check a cell, if it is 0, I'd like it to copy all the time windows in the row above and paste into the time windows that read 0 (the row below).

    The error I get is "Loop without Do"

    Here is what I have so far.


    Please Login or Register  to view this content.
    If someone knows what is going on and could explain the reasoning I would greatly appreciate it. I really want to learn this coding as it will make my life much much easier.

    Thanks!

    Jon
    Last edited by jobell; 06-12-2012 at 11:53 AM.

  2. #2
    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,630

    Re: Do Loop error - first week with VBA

    You need code tags to comply with the forum rules ... which you should read.

    To save you a little time, it's probably more to do with the If ... Else ... Else ... and no End If. Not sure about the validity of two Else's but the proof is in the eating.
    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


  3. #3
    Registered User
    Join Date
    06-12-2012
    Location
    Milwaukee
    MS-Off Ver
    Excel 2007/2010
    Posts
    18

    Re: Do Loop error - first week with VBA

    Thanks! I'll read over that.

    It appears it has something to do with the Else. When I run the code with both Elses comented out, it runs indefinately.

    Please Login or Register  to view this content.

  4. #4
    Forum Expert JapanDave's Avatar
    Join Date
    06-10-2008
    Location
    The grid, I got in!
    MS-Off Ver
    Excel 2010/13
    Posts
    1,696

    Re: Do Loop error - first week with VBA

    Try this,

    Please Login or Register  to view this content.
    Be fore warned, I regularly post drunk. So don't take offence (too much) to what I say.
    I am the real 'Napster'
    The Grid. A digital frontier. I tried to picture clusters of information as they moved through the computer. What did they look like? Ships? motorcycles? Were the circuits like freeways? I kept dreaming of a world I thought I'd never see. And then, one day...

    If you receive help please give thanks. Click the * in the bottom left hand corner.

    snb's VBA Help Files

  5. #5
    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,630

    Re: Do Loop error - first week with VBA

    You have an alternative solution.

    However, if you want to use Do, it usually takes the format Do Until or Do While. You have also commented out the break out Exit Do.


    Regards, TMS

  6. #6
    Forum Expert JapanDave's Avatar
    Join Date
    06-10-2008
    Location
    The grid, I got in!
    MS-Off Ver
    Excel 2010/13
    Posts
    1,696

    Re: Do Loop error - first week with VBA

    whoops, sorry Tm, I did not see you had posted.

  7. #7
    Registered User
    Join Date
    06-12-2012
    Location
    Milwaukee
    MS-Off Ver
    Excel 2007/2010
    Posts
    18

    Re: Do Loop error - first week with VBA

    Great! Thanks a lot guys!

    JapanDave - that code is quick and very neat! It fills empty values in column Y with no problem, however when there is a "0" in column Y, there are also 0s in Y - AP that I need to be filled in with the row's values above.

    TMShucks - thanks for the input. I used a do loop because that was one of the subscripts I learned the other day. I am completely unfamiliar with the coding that JapanDave used and am starting to realize that there are many, many ways to skin the cat.

    Thank you both for the knowledge! Like I said, I've only just begun digging into VBA so any explainations of how your code works, or the suggestions you've made above will work, I would really appreciate it!

    Jon

  8. #8
    Forum Expert JapanDave's Avatar
    Join Date
    06-10-2008
    Location
    The grid, I got in!
    MS-Off Ver
    Excel 2010/13
    Posts
    1,696

    Re: Do Loop error - first week with VBA

    I don't follow. Are you saying you have the letter "o"?

  9. #9
    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,630

    Re: Do Loop error - first week with VBA

    I suggest that you upload a sample workbook. We seem to be clutching at straws tying to understand your requirements.

    Regards, TMS

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

    Re: Do Loop error - first week with VBA

    Hi Jobell,

    I altered your code:

    Please Login or Register  to view this content.
    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

  11. #11
    Registered User
    Join Date
    06-12-2012
    Location
    Milwaukee
    MS-Off Ver
    Excel 2007/2010
    Posts
    18

    Re: Do Loop error - first week with VBA

    Thanks guys! I will give that code a shot here this morning. Row 1 has headers so I assume starting in 2 should be fine.

    TM - how do I upload a workbook to the forum?

  12. #12
    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,630

    Re: Do Loop error - first week with VBA

    Click on Go Advanced. Click on the Paperclip icon or Manage Attachments. Navigate to your file ... follow the instructions.

    Regards, TMS

  13. #13
    Registered User
    Join Date
    06-12-2012
    Location
    Milwaukee
    MS-Off Ver
    Excel 2007/2010
    Posts
    18

    Re: Do Loop error - first week with VBA

    Quote Originally Posted by xladept View Post
    Hi Jobell,

    I altered your code:

    Please Login or Register  to view this content.
    Works great! Thanks!

    I have a question about how this works if you dont mind!

    Please Login or Register  to view this content.
    The ActiveCell at the end of that line - when I commented that out of the code it no longer pasted the copied cells to the cells below with 0s. When I removed the comment ' and ran it again, it pasted. How does that work? I just don't understand the logic behind it and would love if you could explain it!

    Thanks!
    Last edited by jobell; 06-13-2012 at 11:14 AM. Reason: clarification

  14. #14
    Registered User
    Join Date
    06-12-2012
    Location
    Milwaukee
    MS-Off Ver
    Excel 2007/2010
    Posts
    18

    Re: Do Loop error - first week with VBA

    orders.xls

    Here is a sample of the workbook I am dealing with.

  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: Do Loop error - first week with VBA

    Hi jobell,

    The ActiveCell at the end of the line is the copy destination - check out the help file for the copy method and all should become clear.

  16. #16
    Registered User
    Join Date
    06-12-2012
    Location
    Milwaukee
    MS-Off Ver
    Excel 2007/2010
    Posts
    18

    Re: Do Loop error - first week with VBA

    Thanks a lot! I didn't realize the help function could be so useful. I appreciate everyone's help!

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

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