+ Reply to Thread
Results 1 to 11 of 11

Code not working properly

  1. #1
    Forum Contributor
    Join Date
    12-02-2013
    Location
    Oklahoma
    MS-Off Ver
    Excel 2010
    Posts
    152

    Code not working properly

    Hi and thanks for all your help thus far.

    This code came largely from you guys and it seemed to pass every test that I could think of, however when put to the ultimate test (that being trying to run it with my actual information) if fails and puts things in the wrong order.

    I can post a workbook if needed (it will take some work to pull the sensitive info out again) but I hoped that perhaps someone could tell me what might make the code fail only when I start adding real information.

    Please Login or Register  to view this content.
    Thanks,
    Tom

  2. #2
    Valued Forum Contributor
    Join Date
    01-19-2010
    Location
    Melbourne Australia
    MS-Off Ver
    latest is Excel 2016. have older versions
    Posts
    624

    Re: Code not working properly

    Hi Tom,

    It would help if there was a bit more clarity about
    if fails and puts things in the wrong order.
    Have you changed the workbook (VBA code excepted of course) since your previous sample was posted, if not the repost that as an assist

    Cheers

    Jmac

  3. #3
    Forum Contributor
    Join Date
    12-02-2013
    Location
    Oklahoma
    MS-Off Ver
    Excel 2010
    Posts
    152

    Re: Code not working properly

    Fair enough. It is supposed to put data on separate pages based on number...anything 400000-401000 should go on all pages while 401000-402000 in certain pages (a group of red pages), 402000-403000 to yellow pages, 403000-404000 - green, and 404000-405000 to blue.

    It seems to work well in tests but when I start filling in all the info it starts copying everything to every page.
    Attached Files Attached Files

  4. #4
    Valued Forum Contributor
    Join Date
    01-19-2010
    Location
    Melbourne Australia
    MS-Off Ver
    latest is Excel 2016. have older versions
    Posts
    624

    Re: Code not working properly

    wild guess without stepping thru code.

    Cell A2 (event code) is set to All (even though you cannot see it without selecting the cell(and so I guess that is what it is doing, how does it get set to something else??

    Cheers

    Jmac1947

    1. Please consider clicking on the * Add Reputation if you think this post has helped you
    2. Mark your thread as SOLVED when question is resolved

  5. #5
    Forum Contributor
    Join Date
    12-02-2013
    Location
    Oklahoma
    MS-Off Ver
    Excel 2010
    Posts
    152

    Re: Code not working properly

    Column A should never change. In fact it could be hidden. It consists on 5 cells; ALL, P1, P2, P3, P4. These are what cause the code to separate the numbers into their respective categories; All for all, P1 for Red, P2 for Yellow, P3 for Green, P4 for blue.

  6. #6
    Valued Forum Contributor
    Join Date
    01-19-2010
    Location
    Melbourne Australia
    MS-Off Ver
    latest is Excel 2016. have older versions
    Posts
    624

    Re: Code not working properly

    testsales-1.xlsm

    Hi Tom,

    OK, now I see Col A as you intended it to work. (I did try to unmerge the cells and populate every row with values but that didnt seem to help, probably made it worse )

    So I stepped through the code with breaks and nothing seemed wrong.

    So I put a break at the "changes" call and checked the sheets when I got there, they all look as I expected, continued the execution and the results are in the attached workbook, they all look correct.

    Conclusion. There is something different in your real data (or spreadsheet for that matter) to what is in your test data and spreadsheet.... bleeding obvious I can hear you say

    Without the actual spreadsheet and data it is hard to proceed much past a couple of general questions.

    1. are you sure that cell A1002 does contain "P1" and so on for the other groups?
    2. it looks like you are not triggering the change of event code correctly with your data so that may be an avenue to try to debug

    just guessing really as it seems to work for me, and indeed in your testing it worked... culprit therefore must be production data

    to be on the safe side, double check my results to prove it is actually working as you expected

    John

  7. #7
    Forum Contributor
    Join Date
    12-02-2013
    Location
    Oklahoma
    MS-Off Ver
    Excel 2010
    Posts
    152

    Re: Code not working properly

    Lol...bleeding obvious...yeah. Well it was worth a shot. I mean, everything checks out in the test runs and I can see no difference in the actual run. There is nothing at all that SHOULD affect the code.

    1. are you sure that cell A1002 does contain "P1" and so on for the other groups?
    column a is as it should be.

    2. it looks like you are not triggering the change of event code correctly with your data so that may be an avenue to try to debug
    I am unsure what you mean. Going through te code step by step there is one point where, when you hover over the code and it shows what is happening, it should say Event Code=4 but instead it shows Event Code=0. I figure that might be the problem, but I cannot understand what would cause that to happen...

    This is where I am talking about.
    Please Login or Register  to view this content.
    Even that, though, seems to change randomly...

  8. #8
    Valued Forum Contributor
    Join Date
    01-19-2010
    Location
    Melbourne Australia
    MS-Off Ver
    latest is Excel 2016. have older versions
    Posts
    624

    Re: Code not working properly

    I wonder.... the named range "events" includes a blank line (row 9), could that be an issue?, you could try to comment out that line and simply assign EventCount = 4 to see what might happen although I have my doubts.


    Please Login or Register  to view this content.
    This is the only spot where the EventCode gets altered (your data seems to start always with "ALL" so if this doesnt get altered by the code above then everything will get everywhere)

    You are testing in lots of places for "", is it possible that your input data actually has " " instead??

    perhaps you should put a simple counter into the code and stop when you get to an even thousand and then step through the next couple of lines to see if you can spot why the eventcode is not being changed. Again you can only do that in you production spreadsheet as we both know it seems to be OK in your test spreadsheet.

    Have you tried to copy 20 rows from say 990 - 1010 from your production data and paste it into your test workbook and see if that "breaks" the test workbook, maybe repeat for all of the P1 - P4 data rows.

    Sorry, I suspect I am not being much help here

    PS.. in your last post you used event code twice whereas I think you mean eventCount
    Last edited by jmac1947; 02-01-2014 at 02:26 AM.

  9. #9
    Forum Contributor
    Join Date
    12-02-2013
    Location
    Oklahoma
    MS-Off Ver
    Excel 2010
    Posts
    152

    Re: Code not working properly

    Wow...I hate that you have gone to all the trouble trying to help me. I just realized that every time I have tried to test this I started at the top of every category...for example in P1 I started my data at number 401000, however when I started my actual data (because I was using data from a previous user) I started one row down.

    Now, I confess that I do not understand why this makes it fail but evidently it does...learned something new. Thanks so much for your help, I am sorry to have bothered you.

    Cheers
    Tom

  10. #10
    Valued Forum Contributor
    Join Date
    01-19-2010
    Location
    Melbourne Australia
    MS-Off Ver
    latest is Excel 2016. have older versions
    Posts
    624

    Re: Code not working properly

    glad you have found at least one problem, hopefully the only problem

    it isnt a problem Tom, nothing like playing at being a detective eh??

    John

  11. #11
    Forum Contributor
    Join Date
    12-02-2013
    Location
    Oklahoma
    MS-Off Ver
    Excel 2010
    Posts
    152

    Re: Code not working properly

    Lol, thanks for your patience.

    It seems to be the only problem (though I do not understand it). It's working fine now.

    Tom

+ 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. Urgent : Macro code is not working properly.
    By kumargourav in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 03-12-2013, 03:26 AM
  2. [SOLVED] Work Order tracker date code not working properly
    By Jeff up North in forum Excel Formulas & Functions
    Replies: 7
    Last Post: 02-15-2013, 03:25 PM
  3. [SOLVED] Conditional Formatting using VBA - Code not working properly
    By Tejas.T in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 12-07-2012, 10:19 AM
  4. email code not working properly in excel 2010
    By techmob in forum Excel General
    Replies: 19
    Last Post: 01-05-2011, 05:37 AM
  5. Help with figuring out some code (not working properly)
    By andyd2k in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 05-19-2005, 07:09 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