View Poll Results: VBA code for sum two column Values

Voters
0. This poll is closed
  • VBA Code

    0 0%
  • VBA programming

    0 0%
Multiple Choice Poll.
+ Reply to Thread
Results 1 to 6 of 6

VBA code to sum values on two different columns and result in another column

Hybrid View

  1. #1
    Registered User
    Join Date
    07-02-2012
    Location
    INDIA
    MS-Off Ver
    Excel 2003
    Posts
    3

    VBA code to sum values on two different columns and result in another column

    Hi friends!

    I need a VBA code to sum values of two columns and result in another column. Please see the example sheet below,

    Data1 data2 data3 total
    5 6 11
    4 5 9
    7 6 9 22

    Can any give me VBA code istead of the formula as =IF(COUNT(A9:C9),SUM(A9:C9),""). Please give a VBA programming code.
    thank you for your assistance in advance.

    Thanks & Regards;
    Senthil Kumar
    Last edited by senthil.ok28; 12-04-2013 at 03:52 PM.

  2. #2
    Forum Moderator alansidman's Avatar
    Join Date
    02-02-2010
    Location
    Steamboat Springs, CO
    MS-Off Ver
    MS Office 365 insider Version 2504 Win 11
    Posts
    24,705

    Re: VBA code to sum values on two different columns and result in another column

    Give this a try:

    Sub total()
        Dim lr As Long
        lr = Range("A" & Rows.Count).End(xlUp).Row
        Range("D2:D" & lr).FormulaR1C1 = "=SUM(RC[-3]:RC[-1])"
    
    End Sub
    Alan עַם יִשְׂרָאֵל חַי


    Change an Ugly Report with Power Query
    Database Normalization
    Complete Guide to Power Query
    Man's Mind Stretched to New Dimensions Never Returns to Its Original Form

  3. #3
    Registered User
    Join Date
    07-02-2012
    Location
    INDIA
    MS-Off Ver
    Excel 2003
    Posts
    3

    Re: VBA code to sum values on two different columns and result in another column

    Thank you alan.

    This helps. However it would be great if you could avoid showing the formula in the Excel sheet. Need a dynamic VBA code that only shows the result using for loop. Example for i = 2 to ..

  4. #4
    Forum Moderator alansidman's Avatar
    Join Date
    02-02-2010
    Location
    Steamboat Springs, CO
    MS-Off Ver
    MS Office 365 insider Version 2504 Win 11
    Posts
    24,705

    Re: VBA code to sum values on two different columns and result in another column

    Try this on for size:

    Sub total()
        Dim MyRange As Range
        Dim i As Long
        Dim lr As Long
        lr = Range("A" & Rows.Count).End(xlUp).Row
    
    For i = 2 To lr
    
        With Worksheets("Sheet1")
          Set MyRange = .Range(.Cells(i, 1), .Cells(i, 3))
          .Cells(i, 4) = WorksheetFunction.Sum(MyRange)
        End With
    Next i
        
    
    End Sub

  5. #5
    Registered User
    Join Date
    07-02-2012
    Location
    INDIA
    MS-Off Ver
    Excel 2003
    Posts
    3

    Re: VBA code to sum values on two different columns and result in another column

    Oh! That was great.Thank you

  6. #6
    Forum Moderator alansidman's Avatar
    Join Date
    02-02-2010
    Location
    Steamboat Springs, CO
    MS-Off Ver
    MS Office 365 insider Version 2504 Win 11
    Posts
    24,705

    Re: VBA code to sum values on two different columns and result in another column

    If that takes care of your original question, please select Thread Tools from the menu link above and mark this thread as SOLVED. 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. [SOLVED] need vba code to compare two column get result of common values of both column
    By breadwinner in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 11-12-2013, 05:42 AM
  2. How to paste the result (already compare values) to columns
    By giallorossi in forum Excel Programming / VBA / Macros
    Replies: 8
    Last Post: 05-20-2013, 03:58 AM
  3. compare 2 columns and result in 3th column
    By danusko in forum Excel Formulas & Functions
    Replies: 6
    Last Post: 10-08-2009, 06:53 AM
  4. capture unique values from 1 column and populate the result into another column
    By teachMeExcel in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 08-28-2009, 05:21 PM
  5. Compare Values in Multiple Columns and return a result
    By edbhome in forum Excel Formulas & Functions
    Replies: 7
    Last Post: 03-18-2009, 09:37 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