+ Reply to Thread
Results 1 to 7 of 7

Help in simplifying code

  1. #1
    Registered User
    Join Date
    04-26-2013
    Location
    DR
    MS-Off Ver
    Excel 2010
    Posts
    14

    Question Help in simplifying code

    Hi!

    I don't how to make some code of my macro more compact.

    Here's and example of the code (it's too long to paste it all here):

    Please Login or Register  to view this content.

    There are a lot more comboboxes like those.

    Thank you!

  2. #2
    Forum Expert Greg M's Avatar
    Join Date
    08-16-2007
    Location
    Dublin. Ireland
    MS-Off Ver
    Office 2016
    Posts
    4,641

    Re: Help in simplifying code

    Hi there,

    I haven't checked your code in detail, but it would seem that your routines are crying out for a few User-Defined Functions!

    I've written a function (mdMyCalculatedValue) which I think will work in conjunction with your "ParaUnidades" routine - obviously you should change the function name to whatever is appropriate (e.g. mdMonthlySales - the first "m" is normally used to define a Module-Level function and the "d" is normally used to indicate that the function returns a Double value)

    The advantage of using User-Defined functions in this way is that any future changes are confined to a single routine.

    If you follow the approach used in the code shown below you should be able to produce the equivalent shortening of the other routines in your application:


    Please Login or Register  to view this content.

    I hope you find the above helpful - please let me know how you get on.

    Regards,

    Greg M

  3. #3
    Registered User
    Join Date
    04-26-2013
    Location
    DR
    MS-Off Ver
    Excel 2010
    Posts
    14

    Re: Help in simplifying code

    That's a lot better, Greg!

    Thank you very much ^^ I'll be using it in other parts of the code.

  4. #4
    Registered User
    Join Date
    04-26-2013
    Location
    DR
    MS-Off Ver
    Excel 2010
    Posts
    14

    Re: Help in simplifying code

    Unfortunately.... I tried to make it better and now I'm facing a problem ^^"


    So I have this which is working fine:

    Please Login or Register  to view this content.
    But then I have this:

    Please Login or Register  to view this content.
    which is working fine as well BUT only because it has i = 1 :P

    What I'm trying to do is:

    use the same counter in "ParaUnidades" for "amntcases".

  5. #5
    Forum Expert Greg M's Avatar
    Join Date
    08-16-2007
    Location
    Dublin. Ireland
    MS-Off Ver
    Office 2016
    Posts
    4,641

    Re: Help in simplifying code

    Hi again,

    Try this:


    Please Login or Register  to view this content.

    Please let me know how this works for you.

    Regards,

    Greg M

  6. #6
    Registered User
    Join Date
    04-26-2013
    Location
    DR
    MS-Off Ver
    Excel 2010
    Posts
    14

    Re: Help in simplifying code

    Greg M... YOU'RE A LIFESAVER.

    Thank you very much ^^ +rep for you again.

  7. #7
    Forum Expert Greg M's Avatar
    Join Date
    08-16-2007
    Location
    Dublin. Ireland
    MS-Off Ver
    Office 2016
    Posts
    4,641

    Re: Help in simplifying code

    Hi again Raquel,

    You're very welcome! Many thanks for your feedback and your kind words - I'm delighted that I was able to help.

    For future reference, you can make your code a LOT more user-friendly by breaking it down into bite-sized chunks as I've tried to illustrate in the following:


    Please Login or Register  to view this content.


    I've assigned names such as "Solids", "Liquids", "Gases" etc. to the various ranges because obviously I have no idea of what sort of data your worksheets contain

    Please let me know if you need help with the above or with anything else.

    Best regards,

    Greg M
    Last edited by Greg M; 11-17-2013 at 02:10 PM. Reason: Added comment re sample names

+ 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. Need help simplifying a code Please
    By Lostinexcel2002 in forum Excel Programming / VBA / Macros
    Replies: 8
    Last Post: 12-10-2008, 07:54 PM
  2. Simplifying the Code
    By marino72 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 05-28-2008, 06:40 PM
  3. Simplifying the code
    By walid66 in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 03-20-2008, 07:53 PM
  4. Simplifying code
    By T De Villiers in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 02-23-2007, 06:50 AM
  5. Simplifying VB code
    By odggi in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 09-30-2006, 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