+ Reply to Thread
Results 1 to 8 of 8

VBA code for summiation in MS Excel

  1. #1
    Registered User
    Join Date
    01-03-2011
    Location
    Bangalore, India
    MS-Off Ver
    MS Excel 2010
    Posts
    49

    VBA code for summiation in MS Excel

    Hello There,

    I am wiritng a macro and got struck badly.
    I have a data from Cell C4 to Dxxx (column D is given as xxx because each day the number of rows get changed).
    In column E, i have given the below code

    Please Login or Register  to view this content.
    Now I am trying to give a Formula in column F but getting struck here...
    If Cell E4<>0,Sum($E$3:E4)
    when it's comes to Cell E5 and if E5<>0,sum($E$3:E5)

    This forumla should be there in all cells which has values in Column E

    As said, the number of rows differs each time.

    Any assistance is highly appreciated!!!

    Thanks!
    Last edited by Srikanth H N; 03-02-2014 at 08:30 PM.

  2. #2
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    48,042

    Re: VBA code for summiation in MS Excel

    Please:

    1) use code tags to comply with the forum rules and
    2) upload a sample workbook

    Regards, TMS
    Trevor Shuttleworth - Retired Excel/VBA Consultant

    I dream of a better world where chickens can cross the road without having their motives questioned

    'Being unapologetic means never having to say you're sorry' John Cooper Clarke


  3. #3
    Forum Expert Olly's Avatar
    Join Date
    09-10-2013
    Location
    Darlington, UK
    MS-Off Ver
    Excel 2016, 2019, 365
    Posts
    6,284

    Re: VBA code for summiation in MS Excel

    Add in the line in red:
    Please Login or Register  to view this content.
    let Source = #table({"Question","Thread", "User"},{{"Answered","Mark Solved", "Add Reputation"}}) in Source

    If I give you Power Query (Get & Transform Data) code, and you don't know what to do with it, then CLICK HERE

    Walking the tightrope between genius and eejit...

  4. #4
    Registered User
    Join Date
    01-03-2011
    Location
    Bangalore, India
    MS-Off Ver
    MS Excel 2010
    Posts
    49

    Re: VBA code for summiation in MS Excel

    Perfect!!! TMS~ Appreciate your very quick assistance!!!
    It's my bad, I did not use code tags to comply with the forum rules and upload a sample workbook.
    Going forward will ensure to follow these...

    But Thanks a ton for providing solution... It's working fine.

    Thanks Much

  5. #5
    Forum Expert
    Join Date
    11-26-2013
    Location
    Colac, Victoria, Australia
    MS-Off Ver
    Excel 2016
    Posts
    1,309

    Re: VBA code for summiation in MS Excel

    Hi Srikanth,

    Your post is not very clear, but I think you are saying that the If Cell E4<>0,Sum($E$3:E4) code is going to be in another macro (or part of the macro). If it is set up the same way as the one you posted, it won't work because the macro converts it to a value BEFORE writing to the cell. (the .value = .value code).

    Try removing the .value =.value code from the WITH statement. This will cause the formula to be written to the cell instead of the value. I assume you don't want the formula there, so AFTER the with statement, select the range and convert it to values. Something like this:

    Please Login or Register  to view this content.
    Hope this helps!

    Regards,

    David

    Please remember, your request is clearer if you attach a sample workbook.
    - Click on Go Advanced and click on the Paper Clip.
    When you reply please make it clear WHO you are responding to by mentioning their name.
    If this has been of assistance, please advise. A little thanks goes a long way.
    - Please click on the *Add Reputation button at the bottom of helpful responses.
    Please mark your thread as SOLVED:
    - Click Thread Tools above your first post, select "Mark your thread as Solved".

  6. #6
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    48,042

    Re: VBA code for summiation in MS Excel

    I would appreciate it if you would edit the original post in this thread and add code tags to comply with forum rules. Strictly speaking, we are not supposed to answer questions that do not comply with the forum rules.

    Adding code tags makes it easier for contributors to copy the code, if necessary. Uploading a sample workbook, whilst not always essential, will ensure that contribitors can see what you are working with and the solution is more likely to be fit for purpose.


    Regards, TMS




    If you are satisfied with the solution(s) provided, please mark your thread as Solved.


    New quick method:
    Select Thread Tools-> Mark thread as Solved. To undo, select Thread Tools-> Mark thread as Unsolved.

    Or you can use this way:

    How to mark a thread Solved
    Go to the first post
    Click edit
    Click Go Advanced
    Just below the word Title you will see a dropdown with the word No prefix.
    Change to Solved
    Click Save


    You may also want to consider thanking those people who helped you by clicking on the little star at the bottom left of their reply to your question.

  7. #7
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    48,042

    Re: VBA code for summiation in MS Excel

    Please note that the solution did not come from me, it was from OllyXLS

  8. #8
    Registered User
    Join Date
    01-03-2011
    Location
    Bangalore, India
    MS-Off Ver
    MS Excel 2010
    Posts
    49

    Re: VBA code for summiation in MS Excel

    Hi OllyXLS,

    Thanks for your assitance. Have 1 more question...

    I am trying to give background clor for those cells that are less than 500K, but getting struck. Any assistance!!!

    here is the code which i have got struck...

    Please Login or Register  to view this content.
    Thanks!

+ 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. Replies: 1
    Last Post: 11-13-2013, 10:28 AM
  2. Adding Text to another cell VB code (Help Tweeking code) (Excel 2007)
    By Excelnoub in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 12-06-2012, 11:37 AM
  3. Code for email alerts from excel isn't working, wrong code possibly?
    By jessthorogood in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 07-27-2012, 01:45 AM
  4. Importing Excel Macros Code from another Excel sheet which has Macro code.
    By arun.pillai in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 01-14-2010, 05:38 PM
  5. stubborn Excel crash when editing code with code, one solution
    By Brian Murphy in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 02-20-2005, 02:06 AM

Tags for this Thread

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