Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

VBA in Excel - Sum of cells

Status
Not open for further replies.

plasmar8

Technical User
Feb 2, 2006
4
0
0
GB
Hi all,

I'm trying to write a bit of code that sums the value of a particular cell (in this case D4) in each of the worksheets in the application and returns the answer in a msgbox.
I've gotten this far but it doesn't work, any ideas?

Sub sumofD4()
Dim sumofD4()
Dim w As Integer
Dim i As Integer
Dim sum As Integer
sum = 0

w = Worksheets.Count
ReDim sumofD4(1 To w)

For i = LBound(sumofD4) To UBound(sumofD4)
sumofD4(i) = Worksheets(i).Range("D4").Value
Next i

For Each sumofD4(i) In Selection
sum = sum + sumofD4(i)
Next sumofD4(i)

MsgBox (i)
End Sub

Thanks in advace Plasmar8
 
Your quite right!
Apologies i'll repost in the right forum.
Thanks,
Ae
 


That would be forum707.

Skip,
[sub]
[glasses]Just traded in my old subtlety...
for a NUANCE![tongue][/sub]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top