+ Reply to Thread
Results 1 to 15 of 15

Can't get "loop" to stop

  1. #1
    Registered User
    Join Date
    05-29-2012
    Location
    London
    MS-Off Ver
    Excel 2007
    Posts
    63

    Can't get "loop" to stop

    Hopefully this is an easy one.....

    I have two sheets "barcodes" and "input". The code works, but I cant get the loop to stop?

    Any ideas - example attached!

    Many thanks
    Attached Files Attached Files

  2. #2
    Forum Contributor arlu1201's Avatar
    Join Date
    09-09-2011
    Location
    Bangalore, India
    MS-Off Ver
    Excel 2003 & 2007
    Posts
    19,166

    Re: Can't get "loop" to stop

    Maybe you can explain what you are trying to achieve with your code?
    If I have helped, Don't forget to add to my reputation (click on the star below the post)
    Don't forget to mark threads as "Solved" (Thread Tools->Mark thread as Solved)
    Use code tags when posting your VBA code: [code] Your code here [/code]

  3. #3
    Forum Guru
    Join Date
    03-12-2010
    Location
    Canada
    MS-Off Ver
    2010 and 2013
    Posts
    4,418

    Re: Can't get "loop" to stop

    Maybe try this (untested):

    Please Login or Register  to view this content.
    abousetta
    Last edited by abousetta; 09-19-2012 at 06:31 AM.
    Please consider:

    Thanking those who helped you. Click the star icon in the lower left part of the contributor's post and add Reputation.
    Cleaning up when you're done. Mark your thread [SOLVED] if you received your answer.

  4. #4
    Registered User
    Join Date
    05-29-2012
    Location
    London
    MS-Off Ver
    Excel 2007
    Posts
    63

    Re: Can't get "loop" to stop

    Hi abousetta,

    It doesn't work because the variable "r" is undefined? Not sure what to change here?

    Thanks

  5. #5
    Registered User
    Join Date
    05-29-2012
    Location
    London
    MS-Off Ver
    Excel 2007
    Posts
    63

    Re: Can't get "loop" to stop

    Hi arlu1201,

    What i'm trying to do is input a unique bar code against the stock number in the "input" sheet. Once this is done i need to then put that stock number against the barcode in "barcodes" sheet.

    Thanks

  6. #6
    Forum Guru
    Join Date
    03-12-2010
    Location
    Canada
    MS-Off Ver
    2010 and 2013
    Posts
    4,418

    Re: Can't get "loop" to stop

    r As Long

    added it above

  7. #7
    Registered User
    Join Date
    05-29-2012
    Location
    London
    MS-Off Ver
    Excel 2007
    Posts
    63

    Re: Can't get "loop" to stop

    I can't get it to work, its hanging on the line?

    PHP Code: 
    .Range("A3:A" 1) = Sheets("Barcodes").Range("A2:A" r

  8. #8
    Forum Guru
    Join Date
    03-12-2010
    Location
    Canada
    MS-Off Ver
    2010 and 2013
    Posts
    4,418

    Re: Can't get "loop" to stop

    Can you walk me through what you want the macro to do? I'm sure it's a minor tweak but if you elaborate I should be able to fix it with less effort.

    abousetta

  9. #9
    Registered User
    Join Date
    05-29-2012
    Location
    London
    MS-Off Ver
    Excel 2007
    Posts
    63

    Re: Can't get "loop" to stop

    I have a list of Barcodes in the "barcode" sheet.

    I then have a list of stock numbers in the "input" sheet.

    I need the macro to take the last unused barcode in the selection "barcodes" and assign it to the next stocknumber (without a barcode assigned)in "input". To complete the task the barcode needs to have the stock number assigned in the "barcode" sheet as well.

    So in theory when I update stock numbers (i.e. put in new ones) I can automatically assign a new barcode.

    I need the macro to stop when it runs out of barcodes, and ideally pop up with an error.

    I hope that makes sense

  10. #10
    Forum Expert tigeravatar's Avatar
    Join Date
    03-25-2011
    Location
    Colorado, USA
    MS-Off Ver
    Excel 2003 - 2013
    Posts
    5,361

    Re: Can't get "loop" to stop

    @Abousetta, the "r" is supposed to be LR, which is what is causing the error. You assigned LR a value, but never assigned r a value, so the range "A2:A" & r becomes "A2:A0" which is causing the error because there is no "A0" cell. Haven't read the rest of what he needs, but that is why the code is erroring.
    Hope that helps,
    ~tigeravatar

    Forum Rules: How to use code tags, mark a thread solved, and keep yourself out of trouble

  11. #11
    Forum Guru
    Join Date
    03-12-2010
    Location
    Canada
    MS-Off Ver
    2010 and 2013
    Posts
    4,418

    Re: Can't get "loop" to stop

    Hi TA,

    Yes, I changed strategies mid coding and didn't account for it. It was way too early in the morning and I hope to get a look at after work when I can concentrate. It's not a difficult task from the OP's description.

    abousetta

  12. #12
    Registered User
    Join Date
    05-29-2012
    Location
    London
    MS-Off Ver
    Excel 2007
    Posts
    63

    Re: Can't get "loop" to stop

    Hi, can anyone shed any light on this yet? I feel the answer is at my fingertips but i cant quite get there!!

    Thank you so much!!!

  13. #13
    Forum Guru
    Join Date
    03-12-2010
    Location
    Canada
    MS-Off Ver
    2010 and 2013
    Posts
    4,418

    Re: Can't get "loop" to stop

    Hi,

    Try this out. I tested the possible scenarios I could think of. Let me know if you need any further tweaks.

    Please Login or Register  to view this content.
    abousetta

  14. #14
    Registered User
    Join Date
    05-29-2012
    Location
    London
    MS-Off Ver
    Excel 2007
    Posts
    63

    Re: Can't get "loop" to stop

    Perfect, this works brilliantly! Thank you so much!

  15. #15
    Forum Guru
    Join Date
    03-12-2010
    Location
    Canada
    MS-Off Ver
    2010 and 2013
    Posts
    4,418

    Re: Can't get "loop" to stop

    Glad I was able to assist.

    Good luck.

    abousetta

+ 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