+ Reply to Thread
Results 1 to 13 of 13

Workhours code wont loop correctly.

  1. #1
    Forum Contributor
    Join Date
    09-08-2009
    Location
    Norway
    MS-Off Ver
    Excel 2002
    Posts
    142

    Workhours code wont loop correctly.

    I'm trying to create a code that does all the shift figuring and hours calculcations automatically, so far it's going pretty well except i'm now having problems looping the code correctly, i know i could have used Loop instead of Goto and stuff but i'd rather stick to code i can actually understand, my question is this; by looking at this code can you see something that is wrong?

    I want it to go down 1 line each time it has completed the calculcations for the row. (3 skift, 2 skift and dagtid) then it should proceed to change the ranged to one line below the first one, and so on until Counter reaches 64.

    Instead of doing this (It counts to 64 correctly it seems since the code ends and doesnt loop indefinately)
    The code doesn't do anything at all it seems which makes me wonder, have i done a big boo boo? :D

    Here is the code;

    Please Login or Register  to view this content.
    Attached Files Attached Files
    Last edited by prefix; 02-08-2011 at 10:34 AM.

  2. #2
    Forum Contributor
    Join Date
    09-08-2009
    Location
    Norway
    MS-Off Ver
    Excel 2002
    Posts
    142

    Re: Workhours code wont loop correctly.

    once again failure to upload any sample.xls because the site gives me a Website error each time i try. I had to add it to a zip archive in order for the upload to work, attachment is 2 posts below.
    Last edited by prefix; 02-08-2011 at 07:20 AM.

  3. #3
    Forum Expert royUK's Avatar
    Join Date
    11-18-2003
    Location
    Derbyshire,UK
    MS-Off Ver
    Xp; 2007; 2010
    Posts
    26,200

    Re: Workhours code wont loop correctly.

    It's not a site problem, I suspect you are uploading files that are bigger than allowed. Maybe if you zipped the file!
    Hope that helps.

    RoyUK
    --------
    For Excel Tips & Solutions, free examples and tutorials why not check out my web site

    Free DataBaseForm example

  4. #4
    Forum Contributor
    Join Date
    09-08-2009
    Location
    Norway
    MS-Off Ver
    Excel 2002
    Posts
    142

    Re: Workhours code wont loop correctly.

    The filesize is 752 kb. and it says maximum filesize for xls. files are 1 000 kb's, or 1 mb.

    So no. that's not the problem. I get the error, "Database error
    The Excel Help Forum database has encountered a problem."

    And it says that staff has been notified.

  5. #5
    Forum Contributor
    Join Date
    09-08-2009
    Location
    Norway
    MS-Off Ver
    Excel 2002
    Posts
    142

    Re: Workhours code wont loop correctly.

    Zipping the file made all the difference though :o Can't believe it didn't support .xls but it worked with zip.
    Attached Files Attached Files

  6. #6
    Forum Contributor
    Join Date
    09-08-2009
    Location
    Norway
    MS-Off Ver
    Excel 2002
    Posts
    142

    Re: Workhours code wont loop correctly.

    Ok, i got one step further, by changing
    Please Login or Register  to view this content.
    [/CODE]


    to
    Please Login or Register  to view this content.
    I was able to have it loop 6 rows down, then something screws up because the code stops running and the 7th row shows a negative value. Anyone have any ideas?

  7. #7
    Forum Contributor
    Join Date
    09-08-2009
    Location
    Norway
    MS-Off Ver
    Excel 2002
    Posts
    142

    Re: Workhours code wont loop correctly.

    Huh. after stepping through the code about 10 times the 8th row turns into; 1881530 25 -1881505 -1881350,04
    So it's REALLY negative now :P


    Edit:

    Upon further inspection i saw that i had missed a few Set's that were needed.

    Added missing sets, problem still persists, value turns negative on row 13, Ferie column is turned into 610,612244897959. and the Timer result is -430,612244897959 . WHY?? :O
    Last edited by prefix; 02-08-2011 at 08:11 AM.

  8. #8
    Forum Contributor
    Join Date
    09-08-2009
    Location
    Norway
    MS-Off Ver
    Excel 2002
    Posts
    142

    Re: Workhours code wont loop correctly.

    The problem seems to be with the Ferie column, as the ones without any Ferie (Holiday) the calculcations are correct but once any vacation is entered it will start going negative. Doubling once for each time the code is run. So far i've tried .Value and .Value2 since the particular Column in question does contain formulas, but it hasn't worked, i'm fresh out of ideas, anyone have any?

  9. #9
    Forum Expert royUK's Avatar
    Join Date
    11-18-2003
    Location
    Derbyshire,UK
    MS-Off Ver
    Xp; 2007; 2010
    Posts
    26,200

    Re: Workhours code wont loop correctly.

    Several of the objects that you have set don't appear to be used

  10. #10
    Forum Contributor
    Join Date
    09-08-2009
    Location
    Norway
    MS-Off Ver
    Excel 2002
    Posts
    142

    Re: Workhours code wont loop correctly.

    Quote Originally Posted by royUK View Post
    Several of the objects that you have set don't appear to be used
    Really ? most of them are, but some might not be used until later, this code isn't completely done, i am testing as i go to make sure everything works. Which ones aren't in use that you can see? I'm fairly sure the problem is with either Ferie or Feriedager, i would like to have them find the value instead of the formula, which i think might be the problem. But whenever i set .value or .value2 it says "Object required." :/

  11. #11
    Forum Contributor
    Join Date
    09-08-2009
    Location
    Norway
    MS-Off Ver
    Excel 2002
    Posts
    142

    Re: Workhours code wont loop correctly.

    Solved the negative issue, i was issuing Feriedager = without thinking that i had dimmed it as range, changed it to Integer and dropped the set, now it doesn't bring out negative numbers, still stops on row 13 though, even though i asked the code to run until Counter = 64, which means it should loop it 64 times, since every runthough should add + 1 to Counter. However this doesn't seem to work. Anyone have a solution? Thanks

  12. #12
    Forum Contributor
    Join Date
    09-08-2009
    Location
    Norway
    MS-Off Ver
    Excel 2002
    Posts
    142

    Re: Workhours code wont loop correctly.

    Ok once again i've tried a different approach and this time i get "Loop without Do" even though it has a do until isempty(activecell) it doesn't seem to pick up on it, could it be because i have Goto inside the code that supposed to loop?

    Please Login or Register  to view this content.
    edit:

    I am now doing this instead;

    Please Login or Register  to view this content.
    STILL The code refuses to run to more than row 13. :-(
    Last edited by prefix; 02-08-2011 at 10:07 AM.

  13. #13
    Forum Contributor
    Join Date
    09-08-2009
    Location
    Norway
    MS-Off Ver
    Excel 2002
    Posts
    142

    Re: Workhours code wont loop correctly.

    FINALLY! I got it. all by myself Turns out goto does interfere with other looping methods. Removing them and just using If Then 'do nothing instead solved everything.

    If anyone would like the final code please let me know

+ 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