+ Reply to Thread
Results 1 to 46 of 46

Macro works during Step Into but not when fully run

  1. #1
    Registered User
    Join Date
    05-28-2014
    Posts
    67

    Macro works during Step Into but not when fully run

    Hi,

    I am running into some issues when trying to run my macro. It's purpose is to grab data from a table and populate them into a separate excel template. For some reason, the code is able to save the templates I've created, but the templates have absolutely no data in them (but I see it work during Step Into). What could be some possible causes and solutions to this problem?

    Thanks!

  2. #2
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,643

    Re: Macro works during Step Into but not when fully run

    Can you upload an example workbook?

    Click on GO ADVANCED and use the paperclip icon to open the upload window.
    If posting code please use code tags, see here.

  3. #3
    Registered User
    Join Date
    05-28-2014
    Posts
    67

    Re: Macro works during Step Into but not when fully run

    Hi, I can't upload a sample workbook, but this is my code:

    Please Login or Register  to view this content.
    I'm sure this could be cleaned up a bit, but for now, this is what I'm working with.

  4. #4
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,643

    Re: Macro works during Step Into but not when fully run

    This shouldn't be where it is in the loop.
    Please Login or Register  to view this content.
    You should first open the template outside the loop, then open it again after you've transferred each states data to the template and saved and closed.

    Another problem I can see is that you should be copying the data to the template before you check to see if the next row will be a different state.

    Which worksheet, in which workbook has the data anyway?

    Is it 'All Plans' in 'ID File.xlsm'?

    By the way, the flow of the code is pretty hard to follow - it's jumping about quite a bit because of the GoTos.

  5. #5
    Registered User
    Join Date
    05-28-2014
    Posts
    67

    Re: Macro works during Step Into but not when fully run

    Yes, that's where my data is.

    So how should it look if I am opening the template before checking and then reopening?

    I've tried this before also, but it didnt seem to work with my previous code.

  6. #6
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,643

    Re: Macro works during Step Into but not when fully run

    I think this is kind of how I would do the code.
    Please Login or Register  to view this content.

  7. #7
    Registered User
    Join Date
    05-28-2014
    Posts
    67

    Re: Macro works during Step Into but not when fully run

    Thanks so much! I will work off of the code that you provided.

    So when I go step by step, I'm reaching a type mismatch error for:

    Please Login or Register  to view this content.

  8. #8
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,643

    Re: Macro works during Step Into but not when fully run

    My fault.

    This,
    Please Login or Register  to view this content.
    should be this.
    Please Login or Register  to view this content.
    Last edited by Norie; 06-05-2014 at 10:15 AM.

  9. #9
    Registered User
    Join Date
    05-28-2014
    Posts
    67

    Re: Macro works during Step Into but not when fully run

    Please Login or Register  to view this content.
    The PlanID, ChildRate and AdultRate are not populating correctly for some reason.
    Last edited by LLL0422; 06-05-2014 at 10:22 AM.

  10. #10
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,643

    Re: Macro works during Step Into but not when fully run

    Apart from that, does it work at all?

  11. #11
    Registered User
    Join Date
    05-28-2014
    Posts
    67

    Re: Macro works during Step Into but not when fully run

    It works for PlanID = 1 but after that, it tries to overwrite the info that had already gone on the template instead of adding on to it.

  12. #12
    Registered User
    Join Date
    05-28-2014
    Posts
    67

    Re: Macro works during Step Into but not when fully run

    I created a sample data table and template for you. These are in the same file for the sample, but I actually have the template in a separate file. Hope this helps.
    Attached Files Attached Files

  13. #13
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,643

    Re: Macro works during Step Into but not when fully run

    Does any of the code I posted work?

  14. #14
    Registered User
    Join Date
    05-28-2014
    Posts
    67

    Re: Macro works during Step Into but not when fully run

    It works up until the PlanID loop.

  15. #15
    Registered User
    Join Date
    05-28-2014
    Posts
    67

    Re: Macro works during Step Into but not when fully run

    I think I see what the issue may be.

    Please Login or Register  to view this content.
    I think colState should look at column L to column AI

    And I had my rState as

    Please Login or Register  to view this content.

  16. #16
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,643

    Re: Macro works during Step Into but not when fully run

    Should colStates actually look at the column with the state which is column C?

    Colums L to AI appear to hold data for multiple plans.

    Could you mock up how the template should look after the data for a state has been transferred to it?

    PS That only needs to be a few lines, just enough so we get a clear picture of what you are after.

  17. #17
    Registered User
    Join Date
    05-28-2014
    Posts
    67

    Re: Macro works during Step Into but not when fully run

    The sample template is in the same file with the others
    Attached Files Attached Files

  18. #18
    Registered User
    Join Date
    05-28-2014
    Posts
    67

    Re: Macro works during Step Into but not when fully run

    It doesn't seem like the code is recognizing that there is a value for PlanID, ChildRate, or AdultRate

  19. #19
    Registered User
    Join Date
    05-28-2014
    Posts
    67

    Re: Macro works during Step Into but not when fully run

    If this help, this was what worked for me when I did it one state at a time,

    Please Login or Register  to view this content.

  20. #20
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,643

    Re: Macro works during Step Into but not when fully run

    The code is getting the values, but it's probably not putting them where you want to.

    Now I'm not sure where the data is meant to go but have you tried stepping through this code to see what's actually happening?
    Please Login or Register  to view this content.
    By the way, why do you have this?
    Please Login or Register  to view this content.
    The first line puts dbAdultRate in 45 cells in column E.

    Also, this would mean that the next lot of data would go 40 odd rows below the previous data, with a big blank space inbetween.
    Please Login or Register  to view this content.
    I say would but this,
    Please Login or Register  to view this content.
    will cause the data to always go in row 14.

    PS Are the effective and expiration dates always the same for a state? Or could they change for each company/plan?

  21. #21
    Registered User
    Join Date
    05-28-2014
    Posts
    67

    Re: Macro works during Step Into but not when fully run

    I shortened the sample version

    Please Login or Register  to view this content.
    But this is necessary because it needs to fill out the rates for ages 0-65.

    Please Login or Register  to view this content.
    This is so that the code starts filling in data from row 14

  22. #22
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,643

    Re: Macro works during Step Into but not when fully run

    The code doesn't fill out rates, it just leaves 45 blank rows which are eventually deleted here.
    Please Login or Register  to view this content.

  23. #23
    Registered User
    Join Date
    05-28-2014
    Posts
    67

    Re: Macro works during Step Into but not when fully run

    That's just very odd...Because it worked before..

  24. #24
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,643

    Re: Macro works during Step Into but not when fully run

    This any better?
    Please Login or Register  to view this content.
    By the way, I've stepped through the code and the PlanID etc are being picked up but I can't tell if they are being put in the correct place in the template.

  25. #25
    Registered User
    Join Date
    05-28-2014
    Posts
    67

    Re: Macro works during Step Into but not when fully run

    Omg that's great! The PlanIDs are where theyre supposed to be! (No clue what changed lol but very lovely!)

    So now that that's all good..is there a way to make it so that it'll add on the data for the other rStates without overwriting what it already populated? Because right now when it loops to the next row, it resets back to

    Please Login or Register  to view this content.

  26. #26
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,643

    Re: Macro works during Step Into but not when fully run

    Perhaps move it to the top of the code,
    Please Login or Register  to view this content.
    and also reset intRowKnt to 14, ready for the next set of data, after the template has been saved and reopened.
    Please Login or Register  to view this content.

  27. #27
    Registered User
    Join Date
    05-28-2014
    Posts
    67

    Re: Macro works during Step Into but not when fully run

    Ah it works!..But it didnt recognize when the state changed..

  28. #28
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,643

    Re: Macro works during Step Into but not when fully run

    Did you change anything?

  29. #29
    Registered User
    Join Date
    05-28-2014
    Posts
    67

    Re: Macro works during Step Into but not when fully run

    I just moved
    Please Login or Register  to view this content.
    to the top

    Please Login or Register  to view this content.
    Last edited by LLL0422; 06-05-2014 at 12:37 PM.

  30. #30
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,643

    Re: Macro works during Step Into but not when fully run

    It think I know what the problem is, here the offset should be +1, not -1.
    Please Login or Register  to view this content.
    If you use -1 then you are comparing rstate to the value in the row above, not the value in the row below.

    PS Did you also add intRowKnt where I suggested?

  31. #31
    Registered User
    Join Date
    05-28-2014
    Posts
    67

    Re: Macro works during Step Into but not when fully run

    Yes, perfect!

    Also, is there a way I can add a condition in then intPlan loop?

    Please Login or Register  to view this content.

    That is why I have

    Please Login or Register  to view this content.
    Last edited by LLL0422; 06-05-2014 at 01:04 PM.

  32. #32
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,643

    Re: Macro works during Step Into but not when fully run

    If you mean if strPlanID is blank then perhaps something like this.
    Please Login or Register  to view this content.
    PS What do you want to happen to intRowKnt if there is a blank?

  33. #33
    Registered User
    Join Date
    05-28-2014
    Posts
    67

    Re: Macro works during Step Into but not when fully run

    If there is a blank then there should be now rows allocated toward it in the template. So ideally, it would continue with the next intRowKnt for the next available plan.

  34. #34
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,643

    Re: Macro works during Step Into but not when fully run

    So you would want to increment intRowKnt by 1 if there's a blank?
    Please Login or Register  to view this content.

  35. #35
    Registered User
    Join Date
    05-28-2014
    Posts
    67

    Re: Macro works during Step Into but not when fully run

    If its blank, then the intRowKnt should be assigned to the next non-blank plan, if that makes sense.

  36. #36
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,643

    Re: Macro works during Step Into but not when fully run

    Not really as the intRowKnt isn't assigned to a plan, it's used to indicate which row the data is to go to in the template.

  37. #37
    Registered User
    Join Date
    05-28-2014
    Posts
    67

    Re: Macro works during Step Into but not when fully run

    When I try to run the whole macro, I get runtime error "Method of Intersect of object_Global failed" when it hits this section:

    Please Login or Register  to view this content.

  38. #38
    Registered User
    Join Date
    05-28-2014
    Posts
    67

    Re: Macro works during Step Into but not when fully run

    Like if the plan is blank, then nothing should happen, and intRowKnt would just proceed for the next plans that are available

  39. #39
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,643

    Re: Macro works during Step Into but not when fully run

    So, where on the template sheet would the next plan go?

    Below the last non-blank plan?
    Please Login or Register  to view this content.
    PS There's no Intersect in that code, or anywhere else, do you have any other code in any of the open workbooks?

  40. #40
    Registered User
    Join Date
    05-28-2014
    Posts
    67

    Re: Macro works during Step Into but not when fully run

    Yes, below the last non-blank plan.

    I believe the template that I'm using may have its own macro, but I have no access to that part of the file. Is there any way around it?

  41. #41
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,643

    Re: Macro works during Step Into but not when fully run

    If the code in the template is event code, eg for a worksheet change event, you could turn off events at the start of your code and turn them back on at the end.
    Please Login or Register  to view this content.

  42. #42
    Registered User
    Join Date
    05-28-2014
    Posts
    67

    Re: Macro works during Step Into but not when fully run

    Where do I add this, at the beginning or the end?

  43. #43
    Registered User
    Join Date
    05-28-2014
    Posts
    67

    Re: Macro works during Step Into but not when fully run

    I also have other macros in the same worksheet.

    Please Login or Register  to view this content.
    did not work

  44. #44
    Registered User
    Join Date
    05-28-2014
    Posts
    67

    Re: Macro works during Step Into but not when fully run

    Okay I think it works, but it says the template needs to be unprotected. Should it work after I unprotect it?

  45. #45
    Registered User
    Join Date
    05-28-2014
    Posts
    67

    Re: Macro works during Step Into but not when fully run

    Sorry, is there a way to make it populate a protected worksheet? I do not have access to the password.
    Last edited by LLL0422; 06-05-2014 at 01:56 PM.

  46. #46
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,643
    Where did you add this code and how did it not work?
    Please Login or Register  to view this content.
    As for the template being protected, how are you expected to do anything with it, especially if you don't have the password?

+ 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. [SOLVED] Macro works in step through but not when run
    By bruizer31 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 07-01-2013, 05:50 PM
  2. Workbook protection macro only works on step thru
    By smokebreak in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 12-01-2010, 06:55 PM
  3. Macro run fails, step through works.
    By SteveAlston in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 06-15-2009, 11:37 PM
  4. Macro Works but not in Debug Step mode
    By Bob Smedley in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 01-31-2006, 12:35 PM
  5. [SOLVED] macro works differently when using the Step Into (F8) feature
    By Dave Y in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 06-23-2005, 11:05 PM

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