+ Reply to Thread
Results 1 to 11 of 11

Macro behaving differently depending on how it is called

  1. #1
    Registered User
    Join Date
    07-01-2013
    Location
    Bradford
    MS-Off Ver
    Excel 2010, Excel 2016
    Posts
    22

    Question Macro behaving differently depending on how it is called

    I have written a macro that creates an Excel sheet that is then given to users. This macro works perfectly when called from the Run Macro box. It also appears to work if an ActiveX button is used. However it does not work correctly with a Form Control button.

    I am using Excel 2013 at work and this is the version that is having problems. I have tested this on my home computer on Excel 2010 and it works perfectly with the Form Control button.

    Does anyone know why Excel 2013 would behave differently when called from a Form Control button than from other methods?

    I realise that this is not a major problem since the ActiveX button works but it is a mystery I would like to solve.

    Many thanks for any help.
    Last edited by louiserace; 05-13-2016 at 09:56 AM.

  2. #2
    Forum Moderator - RIP Richard Buttrey's Avatar
    Join Date
    01-14-2008
    Location
    Stockton Heath, Cheshire, UK
    MS-Off Ver
    Office 365, Excel for Windows 2010 & Excel for Mac
    Posts
    29,464

    Re: Macro behaving differently depending on how it is called

    Hi,

    It works OK for me using 2013. Are you perhaps using a Mac at work and Windows at home.

    Just an observation but disabling screen updating would be easier on the eye and speed things up a bit.

    It's perhaps a bit late now since you've put a significant amount of work into this, but for any future development consider the two elements of data capture and final reporting. The two require quite different treatments.

    A lot of people start by designing the form that they expect to see as the final report or which at first glance seems the best way of capturing data, and then wonder why it's so difficult to subsequently analyse and summarise or extract information from it.

    You should always capture data in a simple two dimensional table and worry about reporting information from it afterwards. Without exception doing this you will always be able to easily obtain management information. Rarely is this the case if you start the other way round.
    You will also throw open the whole wonderful world of the powerful Pivot table functionality.
    Richard Buttrey

    RIP - d. 06/10/2022

    If any of the responses have helped then please consider rating them by clicking the small star icon below the post.

  3. #3
    Registered User
    Join Date
    07-01-2013
    Location
    Bradford
    MS-Off Ver
    Excel 2010, Excel 2016
    Posts
    22

    Re: Macro behaving differently depending on how it is called

    Thanks for looking at it. I am using Windows at both home and work. The only difference is that at work I am on Windows 7 and at home I am on Windows 10.

    If I disable screen updating then people think it is not doing anything and start trying to stop it.

    The whole point of the Macro was to take the data that the main school application gives and then produce the end form.

    This end form is what has been requested by my school and cannot be changed. Also the data application that the school uses is extremely limited in what format reports are produced.

    The macro is trying to make the path between these two things easier.

  4. #4
    Forum Moderator - RIP Richard Buttrey's Avatar
    Join Date
    01-14-2008
    Location
    Stockton Heath, Cheshire, UK
    MS-Off Ver
    Office 365, Excel for Windows 2010 & Excel for Mac
    Posts
    29,464

    Re: Macro behaving differently depending on how it is called

    Re screen updating. I'd still disable it and use a progress bar or even just the status bar to let the user know things are still progressing.

    I wasn't suggesting for one minute that the end form should be changed. I was simply suggesting that it would be more efficient to use a normalised 2 dimensional table (or tables) of data as the source for populating the final form.

    When you say the Form Control button doesn't behave 'correctly' what does happen?

    Have you tried toggling a BreakPoint on the first line of the CreateLists procedure and then stepping through to see where things go awry?

  5. #5
    Registered User
    Join Date
    07-01-2013
    Location
    Bradford
    MS-Off Ver
    Excel 2010, Excel 2016
    Posts
    22

    Re: Macro behaving differently depending on how it is called

    Things only go wrong if I don't step through the program. So I have tracked the problem by moving the breakpoint slowly through the program. I have attached a picture showing the VBA and the sheet being created.

    As you can see the last filter and copy appear to be from the wrong sheet.

    If I put the break point on the lines before this and step through the code it works perfectly.
    Attached Images Attached Images

  6. #6
    Forum Moderator - RIP Richard Buttrey's Avatar
    Join Date
    01-14-2008
    Location
    Stockton Heath, Cheshire, UK
    MS-Off Ver
    Office 365, Excel for Windows 2010 & Excel for Mac
    Posts
    29,464

    Re: Macro behaving differently depending on how it is called

    Hi,

    It seems to work OK for me. i.e. it copies the filtered column I values on the Raw Data Sheet to E6 on the Attendance Summary Groups sheet. You say this last Copy is from the wrong sheet. If not the Raw Data sheet which sheet should be copied?

    Are you sure that in stepping through the macro and presumably jumping back to Excel to see the effect you haven't inadvertently changed the Active 'Raw Data' sheet to some other sheet? This is quite easy to do when you look to see what is happening to two sheets.

    It's always advisable to fully qualify which ranges you are dealing with by including the sheet reference in a VBA instruction. i.e. instead of just

    Formula: copy to clipboard
    Please Login or Register  to view this content.

    always use

    Formula: copy to clipboard
    Please Login or Register  to view this content.


    Note 'Raw_Data' is the VBA sheet code name not the tab name. You should always use code named rather than the string text of the tab names which are too easily changed and in which case would cause your macro to fall over. Similarly always pass the sheet code name to a procedure rather than the sheet name string.

  7. #7
    Registered User
    Join Date
    07-01-2013
    Location
    Bradford
    MS-Off Ver
    Excel 2010, Excel 2016
    Posts
    22

    Re: Macro behaving differently depending on how it is called

    It is supposed to be copying from the raw data sheet but if you look at the screen print it has filtered and copied from the summary sheet.

    The reason I kept moving the break point forward was to stop problems like me changing sheets in the middle. This screen print was taken at that break point and nothing else had been done until that point. I only changed sheets to see what was happening at the break point. Then I stopped the macro.

  8. #8
    Forum Moderator - RIP Richard Buttrey's Avatar
    Join Date
    01-14-2008
    Location
    Stockton Heath, Cheshire, UK
    MS-Off Ver
    Office 365, Excel for Windows 2010 & Excel for Mac
    Posts
    29,464

    Re: Macro behaving differently depending on how it is called

    What do you mean by the Summary Sheet? It's copying from the Attendance Raw Data sheet column I.

    And when I step through it works as I'd expect. I don't see the stuff you show in column D in your picture. Have you checked the file you uploaded to the forum by downloading it, rather than using one which may be after that?

  9. #9
    Registered User
    Join Date
    07-01-2013
    Location
    Bradford
    MS-Off Ver
    Excel 2010, Excel 2016
    Posts
    22

    Re: Macro behaving differently depending on how it is called

    The file that I posted to the forum was created specifically for the forum since I had to take any names out but I have just downloaded that version and the problem still exists.

    On the picture that I posted earlier it shows the copy and paste area that were selected by the previous statement. These are on the Attendance Summary Groups sheet.

    As I stated at the start of this message, the problem only occurs if I run it from the Form Control button and does not occur if I step through the macro in any way before I get to that point. It also does not occur on my home computer.

  10. #10
    Forum Moderator - RIP Richard Buttrey's Avatar
    Join Date
    01-14-2008
    Location
    Stockton Heath, Cheshire, UK
    MS-Off Ver
    Office 365, Excel for Windows 2010 & Excel for Mac
    Posts
    29,464

    Re: Macro behaving differently depending on how it is called

    This is very confusing

    I can step through and also F5 to run the macro to its conclusion in the VBE and get the results expected.

    I also put a break on the first line of the macro that is actioned by both the buttons and clicked each one in turn and stopped the macro when they both came to the break.

    Finally I removed the break and ran the macro from both buttons neither of which left me with what you show in the picture and produced what I would expect to see.

    I'm therefore struggling to understand the cause.

  11. #11
    Registered User
    Join Date
    07-01-2013
    Location
    Bradford
    MS-Off Ver
    Excel 2010, Excel 2016
    Posts
    22

    Re: Macro behaving differently depending on how it is called

    Thanks for all your help. I managed to solve it by stating the sheet name. However I do not understand why only the last few copies from the sheet required this and the first two always worked.
    The attached code worked every time but in the end I did change the first two to match the rest.


    Please Login or Register  to view this content.

+ 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] VBA code behaving differently when stepping
    By Durarara in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 03-18-2016, 05:20 PM
  2. [SOLVED] 2 copies of Excel 2010 behaving differently.
    By JennyW1983 in forum Excel Formulas & Functions
    Replies: 1
    Last Post: 11-09-2015, 04:36 AM
  3. Replies: 9
    Last Post: 07-17-2015, 04:08 PM
  4. Active Macro behaving Inactively?
    By EverGreen1231 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 04-03-2014, 11:47 AM
  5. [SOLVED] Enable / Disable Macros behaving differently in Excel 2003 from Windows XP to Windows 7
    By TC1980 in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 06-21-2013, 09:09 AM
  6. macro behaving different in vista with excel 2007
    By CDPRINT in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 09-17-2010, 10:43 AM
  7. [SOLVED] Alt-Tab works differently if Form called from Menu or Buttonbar Icon
    By seisman in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 08-02-2005, 06:05 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