I need a vba that will do the calculation of the data and paste the result to column B
so plz look sir
plz see the attached file
I need a vba that will do the calculation of the data and paste the result to column B
so plz look sir
plz see the attached file
How does this formula work for you?
=SUM(C2:AZ2)
Write it to B2 and copy down. It will add up the 50 numbers to right of B2. Blanks and text will be counted as zero.
I have presumed that you might not have more than 50 numbers in a row. If that estimate is too big, reduce the sum range. Consider Z2 instead of AZ2 for a possible maximum of 24 used columns C:Z. The next column after AZ is BA. Therefore, extending the sum range to BZ would add another 26 numbers to the sum range.
The code below would do the same thing using VBA.
Sub WriteRowTotals()
' 16 Jul 2019
Dim Rl As Long, Cl As Long
Dim SumRng As Range
Dim R As Long
' re-define workbook if the workbook isn't the one containing the code
' replace "Sheet1" with tab name
With ThisWorkbook.Worksheets("Sheet1")
Rl = .Cells(.Rows.Count, "A").End(xlUp).Row
Cl = .UsedRange.Columns.Count
' row 2 is the first row to sum up
For R = 2 To Rl
Set SumRng = .Range(.Cells(R, "C"), .Cells(R, Cl))
' write the result to column B
.Cells(R, "B").Value = Application.Sum(SumRng)
Next R
End With
End Sub