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 Chriss Miller 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
Joined
Feb 2, 2006
Messages
4
Location
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
 
Shouldn't this question be asked in the Visual Basic for Applications forum? I don't see anything that suggests your question relates at all to Access.

Duane
Hook'D on Access
MS Access MVP
 
Your quite right!
Apologies i'll repost in the right forum.
Thanks,
Ae
 


That would be forum707.

Skip,

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

Part and Inventory Search

Sponsor

Back
Top