Consulting

Results 1 to 5 of 5

Thread: Sum the total value for that column

  1. #1

    Smile Sum the total value for that column

    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?

  2. #2
    VBAX Guru Kenneth Hobs's Avatar
    Joined
    Nov 2005
    Location
    Tecumseh, OK
    Posts
    4,956
    Location
    Welcome to the forum! It is recommended that you place code inside VBA code tags.

    [VBA]vResult = .Sum(Range("J1:J" & rngcell.row))[/VBA]

  3. #3
    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

  4. #4
    Mac Moderator VBAX Guru mikerickson's Avatar
    Joined
    May 2007
    Location
    Davis CA
    Posts
    2,778
    Wouldn't a SUMIF work?
    What is the result you desire?

  5. #5
    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

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •