+ Reply to Thread
Results 1 to 9 of 9

Macro problem - loops theough user defined functions not called in macro

  1. #1
    Registered User
    Join Date
    01-18-2013
    Location
    Perth, Australia
    MS-Off Ver
    Excel 2010
    Posts
    6

    Macro problem - loops theough user defined functions not called in macro

    I have been following this forum for some time but this is my first post. I am hoping that the wisdom out there can point me in the right direction to fix this problem. I have scoured the internet to no avail.

    I have been compiling a workbook with many formulas, named ranges and several macros. This macro (below) has worked correctly a couple of times (step through) but usually starts to loop through the user defined functions and adds a number or rows incorrectly. I have deleted all the macros and named ranges that are not used and checked all the formulas. I am at a loss what else to do and any advice would be greatly appreciated.

    Please Login or Register  to view this content.
    Last edited by beccyclaire; 01-24-2016 at 09:50 AM.

  2. #2
    Forum Expert
    Join Date
    12-14-2012
    Location
    London England
    MS-Off Ver
    MS 365 Office Suite.
    Posts
    8,448

    Re: Macro problem - loops theough user defined functions not called in macro

    You have an error in your code.

    Enable errors and alerts and Screen Updates

    Then step through your code

    It normally happens at Match, Find Open etc.

    So you could insert
    Please Login or Register  to view this content.
    before match and
    Please Login or Register  to view this content.
    after match

    Ahh you are expecting an error with match. I guess that will be your problem.
    Last edited by mehmetcik; 01-24-2016 at 02:20 PM.
    My General Rules if you want my help. Not aimed at any person in particular:

    1. Please Make Requests not demands, none of us get paid here.

    2. Check back on your post regularly. I will not return to a post after 4 days.
    If it is not important to you then it definitely is not important to me.

  3. #3
    Forum Moderator zbor's Avatar
    Join Date
    02-10-2009
    Location
    Croatia
    MS-Off Ver
    365 ProPlus
    Posts
    15,592

    Re: Macro problem - loops theough user defined functions not called in macro

    Your post does not comply with Rule 3 of our Forum RULES. Use code tags around code.

    Posting code between [CODE]Please [url=https://www.excelforum.com/login.php]Login or Register [/url] to view this content.[/CODE] tags makes your code much easier to read and copy for testing, it also maintains VBA formatting.

    Highlight your code and click the # icon at the top of your post window. More information about these and other tags can be found here



    (This thread should receive no further responses until this moderation request is fulfilled, as per Forum Rule 7)

  4. #4
    Registered User
    Join Date
    01-18-2013
    Location
    Perth, Australia
    MS-Off Ver
    Excel 2010
    Posts
    6
    Quote Originally Posted by mehmetcik View Post
    You have an error in your code.

    Enable errors and alerts and Screen Updates

    Then step through your code

    It normally happens at Match, Find Open etc.

    So you could insert
    Please Login or Register  to view this content.
    before match and
    Please Login or Register  to view this content.
    after match

    Ahh you are expecting an error with match. I guess that will be your problem.
    Ahh, I thought the ErrHandler would do something. I'll try your suggestion, thanks for the prompt reply!

  5. #5
    Registered User
    Join Date
    01-18-2013
    Location
    Perth, Australia
    MS-Off Ver
    Excel 2010
    Posts
    6

    Re: Macro problem - loops theough user defined functions not called in macro

    I fixed the code some head scratching and reviews of many helpful forum posts. The problem with the loop was rows added during the loop weren't included. Also I used resize to add rows which worked better with more than 1 row to add (for example below).

    Please Login or Register  to view this content.
    The code works but still loops through the User Defined Functions (as do some other macros in the workbook). This makes the code run more slowly. Its not too much of a problem but I wondered if there was a way to stop it? Thanks for any advice.

  6. #6
    Forum Expert
    Join Date
    12-14-2012
    Location
    London England
    MS-Off Ver
    MS 365 Office Suite.
    Posts
    8,448

    Re: Macro problem - loops theough user defined functions not called in macro

    Ok there is a solution, not ideal but it will help.

    Declare a public variable preferably in your personal workbook


    Please Login or Register  to view this content.

    Then in your macro

    Please Login or Register  to view this content.
    Then in every other Macro

    Please Login or Register  to view this content.

  7. #7
    Registered User
    Join Date
    01-18-2013
    Location
    Perth, Australia
    MS-Off Ver
    Excel 2010
    Posts
    6

    Re: Macro problem - loops theough user defined functions not called in macro

    I see what you have done mehmetcik! A clever workaround that I would not have thought of. Thanks very much for your quick response!

  8. #8
    Forum Contributor
    Join Date
    01-08-2016
    Location
    Cagayan De Oro City, Philippines
    MS-Off Ver
    2013
    Posts
    152

    Re: Macro problem - loops theough user defined functions not called in macro

    You can also try turning of calculations if your user defined functions are used as formulas on the sheet.....Application.Calculations = xlManual.......dont forget to store the original value so you can set it back afterwards.

  9. #9
    Registered User
    Join Date
    01-18-2013
    Location
    Perth, Australia
    MS-Off Ver
    Excel 2010
    Posts
    6

    Re: Macro problem - loops theough user defined functions not called in macro

    gbeats101, that might be what it is. I have used the UDFs in formulas but on a different sheet. They list unique values and concatenate lists, I'll give it a try.

    Thanks for the advice.

+ 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] User-defined type not defined on Copy to Clipboard Macro
    By vamosj in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 09-23-2015, 11:31 AM
  2. User Defined function getting called for all the formula calculation cells
    By 1man in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 06-13-2014, 08:36 AM
  3. user defined macro to replace certain characters in a string based on user input
    By whatappears in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 12-17-2012, 06:25 PM
  4. Problem with loops/recorded macro
    By yookd in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 08-10-2010, 06:39 PM
  5. [SOLVED] User Defined Functions in the Personal Macro Workbook
    By Nate in forum Excel General
    Replies: 2
    Last Post: 05-11-2006, 11:35 AM
  6. [SOLVED] Using user defined workbook name in macro worksheet functions
    By Mark in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 04-06-2005, 02:06 PM
  7. How to: User Form to assign a user defined range to a macro variab
    By TrevTrav in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 03-22-2005, 04:06 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