PDA

View Full Version : Sum the total value for that column



alexandro88
10-28-2011, 12:18 AM
Worksheets("Sheet3").Select
With Application.WorksheetFunction

For Each rngcell In Range("M1:M" & Range("A" & Rows.Count).End(xlUp).Row)

If InStr(1, Left(rngcell.Value, 5), "SFET4") Then
vResult = .Sum(Range("J1:J")) + vResult
ElseIf InStr(1, Left(rngcell.Value, 5), "SFET3") Then
zResult = .Sum(Range("J1:J")) + zResult
End If

Next

MsgBox vResult
MsgBox zResult

End With

Hi, my code will stuck at
vResult = .Sum(Range("J1:J")) + vResult

Any1 can help me?

Kenneth Hobs
10-28-2011, 05:14 AM
Welcome to the forum! It is recommended that you place code inside VBA code tags.

vResult = .Sum(Range("J1:J" & rngcell.row))

alexandro88
10-29-2011, 12:32 AM
Thank Kenneth. It work.
However, the sum of total value SFET4 and SFET3 will mixed.

For Each rngcell In Range("M1:M" & Range("A" & Rows.Count).End(xlUp).Row)

If InStr(1, Left(rngcell.Value, 5), "SFET4") Then
vResult = .Sum(Range("J1:J" & rngcell.Row))
ElseIf InStr(1, Left(rngcell.Value, 5), "SFET3") Then
zResult = .Sum(Range("J1:J" & rngcell.Row))
End If
Next

MsgBox vResult
MsgBox zResult

mikerickson
10-29-2011, 07:45 AM
Wouldn't a SUMIF work?
What is the result you desire?

alexandro88
10-29-2011, 09:21 AM
hi mikerickson,

Thank. I already figure out how to solve that issue.
However, I got another issue.
If i want to search date I manually set with the date in the list. How should i write the code?

Example:
Today : 28/10/2011


In my list got many date:
26/10/2011
27/10/2011
28/10/2011