+ Reply to Thread
Results 1 to 13 of 13

Multiple Level Addition using Macros

  1. #1
    Registered User
    Join Date
    02-10-2016
    Location
    India
    MS-Off Ver
    Office 2013
    Posts
    7

    Multiple Level Addition using Macros

    I have few items grouped on multiple levels, with individual sub levels having again individual components.
    Capture.PNG
    I need macro to calculate weight of each assly level based on its no of child parts and weight of main assly and sub assly again based on individual totals only.

    I am putting another image to view the formulas I have used. Only child component have individual values. Rest are all added up.
    Capture5.PNG

    Thanks in Advance

  2. #2
    Forum Guru xladept's Avatar
    Join Date
    04-14-2012
    Location
    Pasadena, California
    MS-Off Ver
    Excel 2003,2010
    Posts
    12,378

    Re: Multiple Level Addition using Macros

    Hello ajayketkar,

    Welcome to the Forum!

    Attach a sample workbook. Make sure there is just enough data to demonstrate your need. Include a BEFORE sheet and an AFTER sheet in the workbook if needed to show the process you're trying to complete or automate. Make sure your desired results are shown, mock them up manually if necessary.

    Remember to desensitize the data.

    Click on GO ADVANCED and use the paperclip icon to open the upload window.

    View Pic
    If I've helped you, please consider adding to my reputation - just click on the liitle star at the left.

    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~(Pride has no aftertaste.)

    You can't do one thing. XLAdept

    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~aka Orrin

  3. #3
    Registered User
    Join Date
    02-10-2016
    Location
    India
    MS-Off Ver
    Office 2013
    Posts
    7

    Re: Multiple Level Addition using Macros

    Quote Originally Posted by xladept View Post
    Hello ajayketkar,

    Welcome to the Forum!

    Attach a sample workbook. Make sure there is just enough data to demonstrate your need. Include a BEFORE sheet and an AFTER sheet in the workbook if needed to show the process you're trying to complete or automate. Make sure your desired results are shown, mock them up manually if necessary.

    Remember to desensitize the data.

    Click on GO ADVANCED and use the paperclip icon to open the upload window.

    View Pic
    Dear xladept,
    As requested I am attaching both the before and after sheet with this reply.After.xlsxBefore.xlsx

    As you can see, the structure of my workbook is such that few assemblies will be made up of different components at different level. But only component will carry individual weights as in case of before.xslx sheet . All the assemblies will represent their weights as added value of their successive level which I have manually added in after.xlsx sheet. So please guide me to develop a micro which will automate the calculation.

    before.JPG after.JPG

  4. #4
    Forum Guru xladept's Avatar
    Join Date
    04-14-2012
    Location
    Pasadena, California
    MS-Off Ver
    Excel 2003,2010
    Posts
    12,378

    Re: Multiple Level Addition using Macros

    Hi Ajay,

    Try this:

    Please Login or Register  to view this content.
    If you haven't used macros before you'll need to go to:
    File- options - trust center -trust center settings - macro settings ,
    the second option down (disable all macros with notification)

    Then - Copy the code to the clipboard

    Open your Workbook

    Press ALT + F11 to open the Visual Basic Editor.

    Select "Module" from the Insert menu

    Type "Option Explicit" then paste the code under it

    With the cursor between Sub and End Sub press F5 (F8 to Single Step)

    OR

    Press ALT + Q to close the code window.

    Press ALT + F8 then double click on the macro name
    *Be sure to save the book with the code as Macro-Enabled

  5. #5
    Registered User
    Join Date
    02-10-2016
    Location
    India
    MS-Off Ver
    Office 2013
    Posts
    7

    Re: Multiple Level Addition using Macros

    Thanks xladept,
    I have tried the code and it works. But, I have few more requirements. How do I retain the formulas in the calculated cell. After running the code I can see that it is calculating the value, but not retaining the formula.
    Also, In my further requirement, my content tree is going to expand till 8 level (A column) for column as well as it may go up to 1000 rows. Another thing is that, if my weight values(currently in C column) are in another column, where do I change the code to calculate the values accordingly?

    One more thing xladept,
    I have noticed that, the loop is considering ''assly'' as key word to distinguish between assemblies and components. I want them to be distinguished only on the basis of successive level difference from column A irrespective of their description.
    Last edited by ajayketkar5; 02-13-2016 at 12:23 AM.

  6. #6
    Forum Guru xladept's Avatar
    Join Date
    04-14-2012
    Location
    Pasadena, California
    MS-Off Ver
    Excel 2003,2010
    Posts
    12,378

    Re: Multiple Level Addition using Macros

    Hi Ajay,

    Thanks for the rep!

    I have tried the code and it works. But, I have few more requirements. How do I retain the formulas in the calculated cell. After running the code I can see that it is calculating the value, but not retaining the formula.
    The code uses accumulators(ST for subtotal and GT for grandtotal) - there is no formula.

    C is the the third column so where I have a "3" is where you would change the code:

    Please Login or Register  to view this content.
    What, exactly, should we key on?

  7. #7
    Registered User
    Join Date
    02-10-2016
    Location
    India
    MS-Off Ver
    Office 2013
    Posts
    7

    Re: Multiple Level Addition using Macros

    Hi xladept,
    I understood the accumulator things. I just want to know whether we can produce formula as I had shown in my after sheet. second thing, my 2nd column content are going to vary, for understanding purpose I have used the component/assembly structure. Hence I want to key in on the first column that is levels.

  8. #8
    Registered User
    Join Date
    02-10-2016
    Location
    India
    MS-Off Ver
    Office 2013
    Posts
    7

    Re: Multiple Level Addition using Macros

    Dear xladept,
    How to key on to the first column, that is levels? Please help me on this.

    Regards
    Ajay

  9. #9
    Forum Guru xladept's Avatar
    Join Date
    04-14-2012
    Location
    Pasadena, California
    MS-Off Ver
    Excel 2003,2010
    Posts
    12,378

    Re: Multiple Level Addition using Macros

    Hi Ajay,

    What will the data look like? What will be different from your sample and what will be the same? Can you post a more relevant sample?

  10. #10
    Registered User
    Join Date
    02-10-2016
    Location
    India
    MS-Off Ver
    Office 2013
    Posts
    7

    Re: Multiple Level Addition using Macros

    Hi xladept,
    I will post the relevent sample soon. Timebeing please see the following macro code. This is used for autogrouping. Can you refer this and update the macro for calculation based on level as we had done it in the previous example.

    Here is the macro

    Please Login or Register  to view this content.
    Regards
    Last edited by ajayketkar5; 03-04-2016 at 07:08 AM.

  11. #11
    Forum Guru xladept's Avatar
    Join Date
    04-14-2012
    Location
    Pasadena, California
    MS-Off Ver
    Excel 2003,2010
    Posts
    12,378

    Re: Multiple Level Addition using Macros

    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



    * Please attend to this

  12. #12
    Forum Guru xladept's Avatar
    Join Date
    04-14-2012
    Location
    Pasadena, California
    MS-Off Ver
    Excel 2003,2010
    Posts
    12,378

    Re: Multiple Level Addition using Macros

    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



    * Please attend to this

  13. #13
    Registered User
    Join Date
    02-10-2016
    Location
    India
    MS-Off Ver
    Office 2013
    Posts
    7

    Re: Multiple Level Addition using Macros

    Hi xladept,
    I have edited my earlier post. I am still working on the data, meanwhile please let me know if you can help me out with that.

+ 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] How to manage one macro recording three smaller macros (in addition to other commands)
    By Faintkitara in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 05-20-2015, 04:33 PM
  2. Posisible to Disable Save As at Program level (not workbook level)??
    By brian6464 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 01-29-2014, 02:49 PM
  3. Random number count and addition with macros/formulas
    By aiims in forum Hello..Introduce yourself
    Replies: 1
    Last Post: 08-06-2013, 07:48 PM
  4. macros that adjust themselves with the addition of rows!
    By petalred in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 07-31-2008, 02:14 PM
  5. Macros security level
    By Rockter in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 05-08-2007, 04:21 PM
  6. Application Level macros
    By modjoe23 in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 08-24-2005, 11:05 AM
  7. [SOLVED] Checking for security level to allow macros to run
    By Klaus in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 08-18-2005, 06: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