+ Reply to Thread
Results 1 to 14 of 14

My code implementation hangs indefinitely and messes up the destination workbook

  1. #1
    Registered User
    Join Date
    11-06-2012
    Location
    ndemene
    MS-Off Ver
    Excel 2010
    Posts
    74

    My code implementation hangs indefinitely and messes up the destination workbook

    Hello to people who read this.

    My code implementation hangs indefinitely (or so it seems) and messes up (at least) the destination workbook.

    Here is my macro (and the workbooks are attached).:
    Please Login or Register  to view this content.
    Like I said, when I run it, it hangs indefinitely however, when I click to close it and then tell Windows to restart the program, it says:
    Run-time error '-2147417848 (80010108):
    Method 'Copy' of object 'Range' failed.
    When I click "Debug", it highlights the following line.:
    Please Login or Register  to view this content.
    Is there something wrong at all or does VBA take really long to work on three to four thousand cells and the error just arises because I cancelled the operation?

    Running the macro should interpret data from the larger excel file/workbook and then transfer that interpretation to the smaller Excel file/workbook. The smaller file should eventually become larger than the currently larger file but I'll call "This workbook" or "the smaller file" since I'm referring to their state before the macro's first fully successful run.

    What I mean by "interpretation", if it's not clear, is that although in some cases, data can be simply copied and pasted, in other cases, the destination data might be different (but based off of) the source data. For example, "this workbook" should look at the larger file and find out the hours someone is working (where the name of the person or another name but let's always consider it to be the name of the person) and put a W at every intersection of the time worked and the name of the person working. If the person doesn't work at a certain time/date, nothing will be put. Any letter other than W is to be put manually (without the use of the macro).

    "This workbook" should be empty before the macro is run as of row 2 and below as well as have no names to the right of S&P, Loto Quebec, and Project.

    For now, there is nothing to do in "this workbook" for "Resources required".

    Date and Day should be copy/pasted. For every one row in the larger file, there needs to be 36 columns in the smaller file (from 6:00 AM to midnight).

    The times are to be interpreted as the union (in math terminology) of "Reg Start" (column L in larger file) and "Reg End" (column M in larger file) as well as "Inst Start" (Column T in larger file) and "Inst End" (Column U in larger file).

    Plan, Work, Flag, Sick, Vac, Training each don't need to be dealth with using the macro (since they use excel formulas or whatever the terminology is - the point is they change dynamically too and without a macro's help).

    Everything on the right of "Project" is to be added there manually (without the help of the macro).

    If skill is "LQ" in the larger file, the name of the person should go to the right of "Loto Quebec" in "this workbook". If it's anything else including S&P in the larger file, it should go in S&P in "this workbook".

    Also, I would like for the process every time the macro is run to continue from the column after the last one processed in the larger file rather than going through the thousands of columns again (unnecessarily) and freezing the window (as well as taking long).
    If more information is needed, just ask.

    Any help would be greatly appreciated!
    Attached Files Attached Files

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

    Re: My code implementation hangs indefinitely and messes up the destination workbook

    I noticed this:

    Please Login or Register  to view this content.
    should be this:

    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

  3. #3
    Registered User
    Join Date
    11-06-2012
    Location
    ndemene
    MS-Off Ver
    Excel 2010
    Posts
    74

    Re: My code implementation hangs indefinitely and messes up the destination workbook

    Actually, I got more accustomed to the debugger and the use of MsgBox which helped me find that problem already but, I guessed the following (using a bit of logic but, I don't fully understand what I did) instead:

    Please Login or Register  to view this content.
    which worked.

    Could you please compare what you did and what I did just for the sake of knowledge?

  4. #4
    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
    48,018

    Re: My code implementation hangs indefinitely and messes up the destination workbook

    Your code starts on the left and finds the last column before the first blank cell. xladept's code starts on the right (using columns.count ) and finds the last non blank cell to the left. Provided there are no blank cells in the row, the result will be the same. xladept's version is "safer" but you would need to cater, if necessary, for columns with a blank header.

    Regards, TMS
    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


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

    Re: My code implementation hangs indefinitely and messes up the destination workbook

    Yes - Actually, you were using xltoLeft when you started on the left - I trust that it's working now????

  6. #6
    Registered User
    Join Date
    11-06-2012
    Location
    ndemene
    MS-Off Ver
    Excel 2010
    Posts
    74

    Re: My code implementation hangs indefinitely and messes up the destination workbook

    Thanks for your answers. Actually, the overall code is still having problems. I fixed some of the logic of the macro code but, now I get the following error.:
    Run-time error '1004':
    Application-defined or object-defined error
    When I click "Debug", the following line gets highlighted.:
    Please Login or Register  to view this content.
    I then changed that line to the following which still has the same run-time error.:
    Please Login or Register  to view this content.
    I even tried the following which failed as well.:
    Please Login or Register  to view this content.
    What must I do to fix this?

    Edit:
    Here is the current copy of the macro code.:
    Please Login or Register  to view this content.
    Last edited by s3a; 11-15-2012 at 05:51 PM.

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

    Re: My code implementation hangs indefinitely and messes up the destination workbook

    It looks like the columnofpersondest is -1 and when you add 1 to it you're trying to move to column 0 which doesn't exist. Alternatively (or also) replacing the word move with cut might work better.

  8. #8
    Registered User
    Join Date
    11-06-2012
    Location
    ndemene
    MS-Off Ver
    Excel 2010
    Posts
    74

    Re: My code implementation hangs indefinitely and messes up the destination workbook

    Are you sure that's what you meant to say?

    I say this since I don't think I'm incrementing columnOfPersonDest; I'm only setting it equal to something that's positive (and non-zero).

  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
    48,018

    Re: My code implementation hangs indefinitely and messes up the destination workbook

    There's no such method for a range of Move. You need to Cut and Paste .


    Regards, TMS

  10. #10
    Registered User
    Join Date
    11-06-2012
    Location
    ndemene
    MS-Off Ver
    Excel 2010
    Posts
    74

    Re: My code implementation hangs indefinitely and messes up the destination workbook

    I improved my macro code yet again and, this time the program runs but "this workbook" doesn't get updated in the first sheet. Only the second sheet gets updated.

    I uploaded the previous NoSensitiveData.zip archive (I renamed it to NoSensitiveData_PreviousOne.zip) to show that the lines of the cells dissapeared when I chose to delete the data in the cells as can be seen in NoSensitiveData_UpToDate.zip.

    I hope I'm getting close but I'm not sure.

    Could someone check this out please?
    Attached Files Attached Files
    Last edited by s3a; 11-15-2012 at 08:36 PM.

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

    Re: My code implementation hangs indefinitely and messes up the destination workbook

    This is your code:

    Please Login or Register  to view this content.
    I've been reading your code for over an hour = and it seems that the column of person dest is the wrong index to use in this block???


    But you say it's running - so checking the logic is next! Have you done any single stepping??
    Last edited by xladept; 11-15-2012 at 08:32 PM.

  12. #12
    Registered User
    Join Date
    11-06-2012
    Location
    ndemene
    MS-Off Ver
    Excel 2010
    Posts
    74

    Re: My code implementation hangs indefinitely and messes up the destination workbook

    I've been reading your code for over an hour [...]
    I appreciate that a lot.

    I forgot to include my macro code in this forum as a non-attachment.:
    Please Login or Register  to view this content.
    I had modified the code I believe you cited as follows since it was mentioned in this thread to be at fault if I remember correctly.:
    Please Login or Register  to view this content.
    but now, I turned it back to what you cited since I prefer having a one-liner for this task. I am mentioning this just in case it's important.

    All in all, the code runs and modifies one of the two fields in the second worksheet of "this workbook" and does nothing else that I intend it to as far as I can see.

    Since you asked, as embarrassing as it is, I have tried stepping through the code a large part of the day today and have been at this for a few days (but, I have a sleep disorder so, it's very often tough for me to focus though).

    As for your remark about the columnOfPerson + 1 parameter, have you checked the inclusion of the following syntax to the code?:
    Please Login or Register  to view this content.
    Last edited by s3a; 11-15-2012 at 11:29 PM.

  13. #13
    Registered User
    Join Date
    11-06-2012
    Location
    ndemene
    MS-Off Ver
    Excel 2010
    Posts
    74

    Re: My code implementation hangs indefinitely and messes up the destination workbook

    I found a really weird flaw. (The rest of the code hasn't changed.):
    Please Login or Register  to view this content.
    Edit: The fact that this if statement does not get incremented is weird since it is in a for loop where the variable that should get incremented is currentColumnDest.

  14. #14
    Registered User
    Join Date
    11-06-2012
    Location
    ndemene
    MS-Off Ver
    Excel 2010
    Posts
    74

    Re: My code implementation hangs indefinitely and messes up the destination workbook

    Okay, I'm starting another thread again since I restarted coding from scratch since I think I overcomplicated this code.:
    http://www.excelforum.com/excel-prog...84#post3011884

+ 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