Sum of columns

chunu

Board Regular
Joined
Jul 5, 2012
Messages
109
Office Version
  1. 2013
Platform
  1. Windows
  2. Mobile
hi,
I want sum of f2:h2 with the following formula, if i remove .value=.value , formula works fine but with .value=.value
only summing f2:g2
Please help.

Code:
With Range("d2").Formula = "=Sum(f2:h2)"
.Value = .Value
     End With

Thanks
 

Excel Facts

Best way to learn Power Query?
Read M is for (Data) Monkey book by Ken Puls and Miguel Escobar. It is the complete guide to Power Query.
Try this:
Code:
Range("D2").Value = Application.WorksheetFunction.Sum(Range("F2:H2"))
 
Last edited:
Upvote 0
Try

Code:
Sub MM1()
With Range("d2")
    .Formula = "=Sum(f2:h2)"
    .Value = .Value
End With
End Sub
 
Upvote 0
What would be the logic behind putting a formula in the cell get the results you want and then remove the formula. Why not use my solution? Just wondering.

Code:
Sub MM1()
With Range("d2")
    .Formula = "=Sum(f2:h2)"
    .Value = .Value
End With
End Sub
[/QUOTE]
 
Upvote 0
I agree....would only do it if there was other cells impacted by that formula !!
 
Upvote 0
Try this:
Code:
Range("D2").Value = Application.WorksheetFunction.Sum(Range("F2:H2"))


Hi,
Thanks for reply
this sum only F2 & G2, H2 not picked
For some reason i want to remove formula after result.
thanks
 
Upvote 0
Hi,
Thanks for reply
this sum only F2 & G2, H2 not picked
The suggestion by My Aswer Is This includes the sum of all 3 cells for me.
BTW, did you also try Michael M's suggestion?


What would be the logic behind putting a formula in the cell get the results you want and then remove the formula. Why not use my solution? Just wondering.
A couple of reasons come to mind for me.

1. The OP was trying to use the idea of formula & replace so the suggestion along those lines indicates what was wrong with the OP's syntax (that is, a learning exercise on that syntax)


2. Relates to coding style/preference. The formula & replace lends itself immediately to the situation of a larger range of sums simply by changing
Code:
With Range("D2:D1000")
whereas the WorksheetFunction approach needs to be changed to Formula/Replace or Evaluate or building a loop (which would be considerably slower as the range gets larger)

Note, I am not suggesting that your solution here was wrong or inferior, just answering your query.
 
Last edited:
Upvote 0
Hi,
sorry guys it was my mistake , formula was in wrong position.
Thanks you all for your help.
 
Upvote 0

Forum statistics

Threads
1,223,893
Messages
6,175,240
Members
452,621
Latest member
Laura_PinksBTHFT

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