Link to home
Start Free TrialLog in
Avatar of ssnoor
ssnoor

asked on

cell sum among row using vb script in excel file

How to calculate the sum between B = C+D+E using vb script  in excel sheet . B is already defined 0 . C - column , D - column and E - column have numeric value It should be affected each row of excel file.Please let me know if anyone know solution.
Avatar of als315
als315
Flag of Russian Federation image

Please, upload sample workbook with expected result
To give you an idea, here is a basic script which opens a file and place the sum formula in column B. Tweak it as per your requirement.

Dim xlAPP
Dim wb,ws
Dim lr

Set xlAPP=CreateObject("Excel.Application")

'Opening source Excel File
Set wb=xlAPP.Workbooks.Open("C:\Test.xlsx")	'Change the file path as required

'Sheet with data, change it as per your requirement
Set ws=wb.Worksheets("Sheet1")

lr=ws.cells(xlAPP.Rows.count,3).end(3)(1).row

ws.range("B2:B" & lr).formula="=SUM(C2:E2)"

wb.Close True

xlAPP.Quit

Open in new window

Avatar of ssnoor
ssnoor

ASKER

Hello Subodh,

Thanks for your reply.  What does it mean by SUM(C2:E2) . It is for only one row .  But I need to sum every row. like following. As for example

A  |  B | C | D | E

Sub | Score | Last Term| Previous Term | Current Term
Eng  | 0 | 20 |30|40
Math |0 |50|90|20
Geo | 0|40|20|10
.Until the end of row in particular excel sheet
I need to sum up on B column(Score) using vb script. Please let me know.

Thanks.
The code does the same thing what you are asking for.

e.g. if the last row with data is 15, the code will insert the Sum formula in the range B2:B15 so that B15 will have a formula =SUM(C15:E15").

Did you test the code? Isn't it inserting the formulas in each row of column B?
Avatar of ssnoor

ASKER

Hello Subodh,

It is not working . Any other solution. It is displaying 0 in B column. Please help me
Avatar of ssnoor

ASKER

Hello,

I attached screen shot . Here is  Apps Submitted =0 . it should be

Apps Submitted = Apps Pending + Apps Running + Apps Completed ( in excel sheet) . Please let me know if anyone has solution
vcore_screen_excel_sheet.jpg
ASKER CERTIFIED SOLUTION
Avatar of Subodh Tiwari (Neeraj)
Subodh Tiwari (Neeraj)
Flag of India image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of ssnoor

ASKER

Hello Neeraj,

You saved my day . Now it is working. Thanks for your help and cooperation.

Regards
Shaiukh
You're welcome Shaiukh! Glad it worked as desired.
Thanks for the feedback!