View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.programming
Gary''s Student Gary''s Student is offline
external usenet poster
 
Posts: 11,058
Default FOR EACH statement

You may need an activate:

Sub Macro1()
Dim w As Worksheet
t = 0
For Each w In Worksheets
w.Activate
t = t + Cells(1, 1)
Next
MsgBox (t)
End Sub

will work. There may be other problems as well

--
Gary's Student


"zhj23" wrote:

I have 3 worksheets,wanted to find the total sum of the values appeared in a
column (F say) in each of the worksheets. My following codes do not give me
the right answer. Instead it sums only the first sheet, but output triple the
total value of the FIRST sheet and ignores the other 2 sheets. Can anyone
help to resolve this. Many thanks.

Dim wkSht As Worksheet
total = 0
For Each wkSht In Worksheets

total = total + Application.Sum(Range("f8.f150"))

Next wkSht

MsgBox ("Total = ") & total