Sum cells of each row in a selected range

ineedmesome

New Member
Joined
Dec 28, 2017
Messages
5
Hi guys,

I wanna sum the cells of each row in "Rentabilité 2" range and have the result in the column right next to it.

Here's the code i made so far, i managed to select the range under "Rentabilité 2", but don't know how to sum each row, do i need a for loop?

Code:
Sub sum()



    Dim lngLastRow As Long
    Dim lngLastCol As Long
    Dim mc As Range
    
    With Worksheets("data").Cells
        Set mc = .Find("Rentabilité 2", LookIn:=xlValues).Offset(2)
            
        If Not mc Is Nothing Then
            lngLastRow = .Cells(Rows.Count, mc.Column).End(xlUp).Row
            lngLastCol = .Cells(mc.Row, Columns.Count).End(xlToLeft).Column
            .Range(mc, Cells(lngLastRow, lngLastCol)).Select
            range_renta2 = .Range(mc, Cells(lngLastRow, lngLastCol)).Select


        End If
        
    End With
    


End Sub



[TABLE="width: 1504"]
<colgroup><col><col><col><col><col span="2"><col><col span="12"><col><col></colgroup><tbody>[TR]
[TD][/TD]
[TD]AC FP Equity[/TD]
[TD]FP FP Equity[/TD]
[TD]MC FP Equity[/TD]
[TD="colspan: 2"]GLE FP Equity[/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD]Date[/TD]
[TD]PX_LAST[/TD]
[TD]PX_LAST[/TD]
[TD]PX_LAST[/TD]
[TD]PX_LAST[/TD]
[TD][/TD]
[TD]Rentabilité[/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD]Scenarii[/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD="colspan: 2"]Rentabilité 2[/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD][/TD]
[TD="align: right"]35,88[/TD]
[TD="align: right"]44,27[/TD]
[TD="align: right"]155,45[/TD]
[TD="align: right"][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD="align: right"]06/09/2016[/TD]
[TD="align: right"]35,785[/TD]
[TD="align: right"]44,095[/TD]
[TD="align: right"]156,15[/TD]
[TD="align: right"]32,16[/TD]
[TD][/TD]
[TD="align: right"]-0,0026513[/TD]
[TD="align: right"]-0,00396[/TD]
[TD="align: right"]0,004493[/TD]
[TD="align: right"]-0,01971[/TD]
[TD][/TD]
[TD="align: right"]30,98275[/TD]
[TD="align: right"]30,9422[/TD]
[TD="align: right"]31,20489[/TD]
[TD="align: right"]30,45885[/TD]
[TD][/TD]
[TD="align: right"]-0,00066[/TD]
[TD="align: right"]-0,00099[/TD]
[TD="align: right"]0,001123[/TD]
[TD="align: right"]-0,004926[/TD]
[TD][/TD]
[/TR]
[TR]
[TD="align: right"]07/09/2016[/TD]
[TD="align: right"]35,98[/TD]
[TD="align: right"]44,605[/TD]
[TD="align: right"]156,45[/TD]
[TD="align: right"]32,405[/TD]
[TD][/TD]
[TD="align: right"]0,00543441[/TD]
[TD="align: right"]0,0115[/TD]
[TD="align: right"]0,001919[/TD]
[TD="align: right"]0,007589[/TD]
[TD][/TD]
[TD="align: right"]31,23428[/TD]
[TD="align: right"]31,4243[/TD]
[TD="align: right"]31,12469[/TD]
[TD="align: right"]31,30166[/TD]
[TD][/TD]
[TD="align: right"]0,001359[/TD]
[TD="align: right"]0,002875[/TD]
[TD="align: right"]0,00048[/TD]
[TD="align: right"]0,0018973[/TD]
[TD][/TD]
[/TR]
[TR]
[TD="align: right"]08/09/2016[/TD]
[TD="align: right"]36,145[/TD]
[TD="align: right"]44,445[/TD]
[TD="align: right"]154,1[/TD]
[TD="align: right"]33,065[/TD]
[TD][/TD]
[TD="align: right"]0,00457542[/TD]
[TD="align: right"]-0,00359[/TD]
[TD="align: right"]-0,01513[/TD]
[TD="align: right"]0,020163[/TD]
[TD][/TD]
[TD="align: right"]31,20746[/TD]
[TD="align: right"]30,95357[/TD]
[TD="align: right"]30,59838[/TD]
[TD="align: right"]31,69771[/TD]
[TD][/TD]
[TD="align: right"]0,001144[/TD]
[TD="align: right"]-0,0009[/TD]
[TD="align: right"]-0,00378[/TD]
[TD="align: right"]0,0050407[/TD]
[TD][/TD]
[/TR]
[TR]
[TD="align: right"]09/09/2016[/TD]
[TD="align: right"]35,805[/TD]
[TD="align: right"]43,855[/TD]
[TD="align: right"]152,2[/TD]
[TD="align: right"]33,34[/TD]
[TD][/TD]
[TD="align: right"]-0,0094511[/TD]
[TD="align: right"]-0,01336[/TD]
[TD="align: right"]-0,01241[/TD]
[TD="align: right"]0,008283[/TD]
[TD][/TD]
[TD="align: right"]30,77279[/TD]
[TD="align: right"]30,65262[/TD]
[TD="align: right"]30,68198[/TD]
[TD="align: right"]31,32337[/TD]
[TD][/TD]
[TD="align: right"]-0,00236[/TD]
[TD="align: right"]-0,00334[/TD]
[TD="align: right"]-0,0031[/TD]
[TD="align: right"]0,0020706[/TD]
[TD][/TD]
[/TR]
[TR]
[TD="align: right"]12/09/2016[/TD]
[TD="align: right"]34,835[/TD]
[TD="align: right"]43,435[/TD]
[TD="align: right"]152[/TD]
[TD="align: right"]32,725[/TD]
[TD][/TD]
[TD="align: right"]-0,027465[/TD]
[TD="align: right"]-0,00962[/TD]
[TD="align: right"]-0,00131[/TD]
[TD="align: right"]-0,01862[/TD]
[TD][/TD]
[TD="align: right"]30,22341[/TD]
[TD="align: right"]30,76749[/TD]
[TD="align: right"]31,02418[/TD]
[TD="align: right"]30,49196[/TD]
[TD][/TD]
[TD="align: right"]-0,00687[/TD]
[TD="align: right"]-0,00241[/TD]
[TD="align: right"]-0,00033[/TD]
[TD="align: right"]-0,004655[/TD]
[TD][/TD]
[/TR]
[TR]
[TD="align: right"]13/09/2016[/TD]
[TD="align: right"]34,745[/TD]
[TD="align: right"]42[/TD]
[TD="align: right"]150,8[/TD]
[TD="align: right"]32,14[/TD]
[TD][/TD]
[TD="align: right"]-0,002587[/TD]
[TD="align: right"]-0,0336[/TD]
[TD="align: right"]-0,00793[/TD]
[TD="align: right"]-0,01804[/TD]
[TD][/TD]
[TD="align: right"]30,98474[/TD]
[TD="align: right"]30,03868[/TD]
[TD="align: right"]30,81975[/TD]
[TD="align: right"]30,50968[/TD]
[TD][/TD]
[TD="align: right"]-0,00065[/TD]
[TD="align: right"]-0,0084[/TD]
[TD="align: right"]-0,00198[/TD]
[TD="align: right"]-0,004509[/TD]
[TD][/TD]
[/TR]
[TR]
[TD="align: right"]14/09/2016[/TD]
[TD="align: right"]34,87[/TD]
[TD="align: right"]41,49[/TD]
[TD="align: right"]147,4[/TD]
[TD="align: right"]31,89[/TD]
[TD][/TD]
[TD="align: right"]0,00359118[/TD]
[TD="align: right"]-0,01222[/TD]
[TD="align: right"]-0,0228[/TD]
[TD="align: right"]-0,00781[/TD]
[TD][/TD]
[TD="align: right"]31,17676[/TD]
[TD="align: right"]30,68778[/TD]
[TD="align: right"]30,36459[/TD]
[TD="align: right"]30,82336[/TD]
[TD][/TD]
[TD="align: right"]0,000898[/TD]
[TD="align: right"]-0,00305[/TD]
[TD="align: right"]-0,0057[/TD]
[TD="align: right"]-0,001952[/TD]
[TD][/TD]
[/TR]
[TR]
[TD="align: right"]15/09/2016[/TD]
[TD="align: right"]35,395[/TD]
[TD="align: right"]41,51[/TD]
[TD="align: right"]147,65[/TD]
[TD="align: right"]32,005[/TD]
[TD][/TD]
[TD="align: right"]0,01494375[/TD]
[TD="align: right"]0,000482[/TD]
[TD="align: right"]0,001695[/TD]
[TD="align: right"]0,0036[/TD]
[TD][/TD]
[TD="align: right"]31,53272[/TD]
[TD="align: right"]31,07997[/TD]
[TD="align: right"]31,11769[/TD]
[TD="align: right"]31,17703[/TD]
[TD][/TD]
[TD="align: right"]0,003736[/TD]
[TD="align: right"]0,00012[/TD]
[TD="align: right"]0,000424[/TD]
[TD="align: right"]0,0008999[/TD]
[TD][/TD]
[/TR]
[TR]
[TD="align: right"]16/09/2016[/TD]
[TD="align: right"]34,925[/TD]
[TD="align: right"]40,605[/TD]
[TD="align: right"]146,65[/TD]
[TD="align: right"]31,13[/TD]
[TD][/TD]
[TD="align: right"]-0,0133677[/TD]
[TD="align: right"]-0,02204[/TD]
[TD="align: right"]-0,0068[/TD]
[TD="align: right"]-0,02772[/TD]
[TD][/TD]
[TD="align: right"]30,6525[/TD]
[TD="align: right"]30,38772[/TD]
[TD="align: right"]30,8546[/TD]
[TD="align: right"]30,2157[/TD]
[TD][/TD]
[TD="align: right"]-0,00334[/TD]
[TD="align: right"]-0,00551[/TD]
[TD="align: right"]-0,0017[/TD]
[TD="align: right"]-0,00693[/TD]
[TD][/TD]
[/TR]
[TR]
[TD="align: right"]19/09/2016[/TD]
[TD="align: right"]35,375[/TD]
[TD="align: right"]41,685[/TD]
[TD="align: right"]149,05[/TD]
[TD="align: right"]31,26[/TD]
[TD][/TD]
[TD="align: right"]0,01280247[/TD]
[TD="align: right"]0,02625[/TD]
[TD="align: right"]0,016233[/TD]
[TD="align: right"]0,004167[/TD]
[TD][/TD]
[TD="align: right"]31,46526[/TD]
[TD="align: right"]31,89126[/TD]
[TD="align: right"]31,5734[/TD]
[TD="align: right"]31,19473[/TD]
[TD][/TD]
[TD="align: right"]0,003201[/TD]
[TD="align: right"]0,006563[/TD]
[TD="align: right"]0,004058[/TD]
[TD="align: right"]0,0010418[/TD]
[TD][/TD]
[/TR]
[TR]
[TD="align: right"]20/09/2016[/TD]
[TD="align: right"]35,275[/TD]
[TD="align: right"]41,46[/TD]
[TD="align: right"]150,05[/TD]
[TD="align: right"]31,065[/TD]
[TD][/TD]
[TD="align: right"]-0,0028308[/TD]
[TD="align: right"]-0,00541[/TD]
[TD="align: right"]0,006687[/TD]
[TD="align: right"]-0,00626[/TD]
[TD][/TD]
[TD="align: right"]30,97719[/TD]
[TD="align: right"]30,89732[/TD]
[TD="align: right"]31,27342[/TD]
[TD="align: right"]30,87122[/TD]
[TD][/TD]
[TD="align: right"]-0,00071[/TD]
[TD="align: right"]-0,00135[/TD]
[TD="align: right"]0,001672[/TD]
[TD="align: right"]-0,001564[/TD]
[TD][/TD]
[/TR]
[TR]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD]The result would be something like this : [/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD][TABLE="width: 336"]
<colgroup><col span="3"><col><col></colgroup><tbody>[TR]
[TD="colspan: 2"]Rentabilité 2[/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD="align: right"]-0,00066[/TD]
[TD="align: right"]-0,00099[/TD]
[TD="align: right"]0,001123[/TD]
[TD="align: right"]-0,004926[/TD]
[TD="align: right"]-0,0054561[/TD]
[/TR]
[TR]
[TD="align: right"]0,001359[/TD]
[TD="align: right"]0,002875[/TD]
[TD="align: right"]0,00048[/TD]
[TD="align: right"]0,0018973[/TD]
[TD="align: right"]0,00661065[/TD]
[/TR]
[TR]
[TD="align: right"]0,001144[/TD]
[TD="align: right"]-0,0009[/TD]
[TD="align: right"]-0,00378[/TD]
[TD="align: right"]0,0050407[/TD]
[TD="align: right"]0,00150245[/TD]
[/TR]
[TR]
[TD="align: right"]-0,00236[/TD]
[TD="align: right"]-0,00334[/TD]
[TD="align: right"]-0,0031[/TD]
[TD="align: right"]0,0020706[/TD]
[TD="align: right"]-0,0067346[/TD]
[/TR]
[TR]
[TD="align: right"]-0,00687[/TD]
[TD="align: right"]-0,00241[/TD]
[TD="align: right"]-0,00033[/TD]
[TD="align: right"]-0,004655[/TD]
[TD="align: right"]-0,0142554[/TD]
[/TR]
[TR]
[TD="align: right"]-0,00065[/TD]
[TD="align: right"]-0,0084[/TD]
[TD="align: right"]-0,00198[/TD]
[TD="align: right"]-0,004509[/TD]
[TD="align: right"]-0,0155367[/TD]
[/TR]
[TR]
[TD="align: right"]0,000898[/TD]
[TD="align: right"]-0,00305[/TD]
[TD="align: right"]-0,0057[/TD]
[TD="align: right"]-0,001952[/TD]
[TD="align: right"]-0,0098099[/TD]
[/TR]
[TR]
[TD="align: right"]0,003736[/TD]
[TD="align: right"]0,00012[/TD]
[TD="align: right"]0,000424[/TD]
[TD="align: right"]0,0008999[/TD]
[TD="align: right"]0,00518001[/TD]
[/TR]
[TR]
[TD="align: right"]-0,00334[/TD]
[TD="align: right"]-0,00551[/TD]
[TD="align: right"]-0,0017[/TD]
[TD="align: right"]-0,00693[/TD]
[TD="align: right"]-0,0174817[/TD]
[/TR]
[TR]
[TD="align: right"]0,003201[/TD]
[TD="align: right"]0,006563[/TD]
[TD="align: right"]0,004058[/TD]
[TD="align: right"]0,0010418[/TD]
[TD="align: right"]0,01486325[/TD]
[/TR]
[TR]
[TD="align: right"]-0,00071[/TD]
[TD="align: right"]-0,00135[/TD]
[TD="align: right"]0,001672[/TD]
[TD="align: right"]-0,001564[/TD]
[TD="align: right"]-0,0019535[/TD]
[/TR]
</tbody>[/TABLE]
[/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
</tbody>[/TABLE]

Thanks in advance !
 

Excel Facts

How to change case of text in Excel?
Use =UPPER() for upper case, =LOWER() for lower case, and =PROPER() for proper case. PROPER won't capitalize second c in Mccartney
Here's one way you could do it, by using Excel's SUM function:

Code:
With Worksheets("data")
    Set mc = .Cells.Find("Rentabilité 2", LookIn:=xlValues).Offset(2)
    If Not mc Is Nothing Then
        lngLastRow = .Cells(Rows.Count, mc.Column).End(xlUp).Row
        lngLastCol = .Cells(mc.Row, Columns.Count).End(xlToLeft).Column
        With .Range(.Cells(mc.Row, lngLastCol + 1), .Cells(lngLastRow, lngLastCol + 1))
            .FormulaR1C1 = "=SUM(RC" & mc.Column & ":RC" & lngLastCol & ")"
            .Value = .Value 'optional, if you want values only, not formulae
        End With
    End If
End With
 
Last edited:
Upvote 0

Forum statistics

Threads
1,223,909
Messages
6,175,310
Members
452,634
Latest member
cpostell

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top