+ Reply to Thread
Results 1 to 9 of 9

Calculate sum and insert text in multiple sheets

  1. #1
    Forum Contributor timtim89's Avatar
    Join Date
    01-05-2012
    Location
    Copenhagen, Denmark
    MS-Off Ver
    Excel 2010
    Posts
    141

    Calculate sum and insert text in multiple sheets

    Hi!

    In all the sheets in the workbook I need to check column F for containing a cell of value "Commission". If it does, the numbers in the cells of the column following "Commission" needs to be summed together and the sum is insertet in the first blank cell following the numbers that are summed.
    Also, if the sum is calculated, in column A I need insertet a text two rows following last cell containing value. It is better shown in the attached workbook. The code is as follows (but not working):

    Please Login or Register  to view this content.
    Any help is appreciated! Thanks in advance.
    Attached Files Attached Files
    Last edited by timtim89; 02-08-2012 at 10:32 AM.

  2. #2
    Forum Contributor arlu1201's Avatar
    Join Date
    09-09-2011
    Location
    Bangalore, India
    MS-Off Ver
    Excel 2003 & 2007
    Posts
    19,166

    Re: Calculate sum and insert text in multiple sheets

    Put this code in a blank module of your file (Press Alt + F11, a code window will open. On the left hand side, you will see Microsoft Excel Objects, right click and select Insert -> Module. Copy this code there)
    Please Login or Register  to view this content.
    If I have helped, Don't forget to add to my reputation (click on the star below the post)
    Don't forget to mark threads as "Solved" (Thread Tools->Mark thread as Solved)
    Use code tags when posting your VBA code: [code] Your code here [/code]

  3. #3
    Forum Contributor timtim89's Avatar
    Join Date
    01-05-2012
    Location
    Copenhagen, Denmark
    MS-Off Ver
    Excel 2010
    Posts
    141

    Re: Calculate sum and insert text in multiple sheets

    Hey Arlette. Thank you so much for the code.
    In the workbook in which I'll use the code I have additional sheets, in which there is no "Commission" found. I got an error message, and added
    Please Login or Register  to view this content.
    but this does that the text (and sometimes sum) are inserted anyway in the sheets. How do I avoid this? That the text and sum are not inserted in sheets in which "Commission" is not found? My bad for the attachment no corresponding to the real data, and thanks again!

  4. #4
    Forum Contributor arlu1201's Avatar
    Join Date
    09-09-2011
    Location
    Bangalore, India
    MS-Off Ver
    Excel 2003 & 2007
    Posts
    19,166

    Re: Calculate sum and insert text in multiple sheets

    Change On Error Resume Next to On Error goto errhandler and then before next i put this line Errhandler:

  5. #5
    Forum Contributor timtim89's Avatar
    Join Date
    01-05-2012
    Location
    Copenhagen, Denmark
    MS-Off Ver
    Excel 2010
    Posts
    141

    Re: Calculate sum and insert text in multiple sheets

    Thank you. It works perfect now

  6. #6
    Forum Contributor timtim89's Avatar
    Join Date
    01-05-2012
    Location
    Copenhagen, Denmark
    MS-Off Ver
    Excel 2010
    Posts
    141

    Re: Calculate sum and insert text in multiple sheets

    Now that I'm applying the macro on the data that I actually need it for, I get an run time error 91 saying "Object variable or With block variable not set". This I got after adding a sheet to the workbook in which the data worked. The macro still works as supposed to, but anyone who can tell me how to get rid of the error message? I attached the workbook once again with the new data and code. Any help is appreciated, and once again: thanks a lot in advance

    Please Login or Register  to view this content.
    Attached Files Attached Files

  7. #7
    Forum Contributor timtim89's Avatar
    Join Date
    01-05-2012
    Location
    Copenhagen, Denmark
    MS-Off Ver
    Excel 2010
    Posts
    141

    Re: Calculate sum and insert text in multiple sheets

    If it helps in any way, I'm also getting the error message if I simply add an empty sheet to the first three sheets (for which the code works).

  8. #8
    Forum Expert OnErrorGoto0's Avatar
    Join Date
    12-30-2011
    Location
    I DO NOT POST HERE ANYMORE
    MS-Off Ver
    I DO NOT POST HERE ANYMORE
    Posts
    1,655

    Re: Calculate sum and insert text in multiple sheets

    That is not how you use an error handler, but you don't need one here anyway
    Please Login or Register  to view this content.
    Good luck.

  9. #9
    Forum Expert dangelor's Avatar
    Join Date
    09-06-2011
    Location
    Indiana, USA
    MS-Off Ver
    365 Pro Plus
    Posts
    2,274

    Re: Calculate sum and insert text in multiple sheets

    Try handling the errors this way...
    Please Login or Register  to view this content.

  10. #10
    Forum Contributor timtim89's Avatar
    Join Date
    01-05-2012
    Location
    Copenhagen, Denmark
    MS-Off Ver
    Excel 2010
    Posts
    141

    Re: Calculate sum and insert text in multiple sheets

    OnErrorGoto0 and dangelor thanks to both of you! If Not Is Nothing line did the trick

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

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