Hi everyone,

I am having problem with these codes. I should sum up the values grouping them via date.

I think the problem is when i add those values. I can't find a workaround for this.

The code is there can someone modify the codes for me.
Any help is greatly appreciated. Thanks.

Code:
Private Sub Command1_Click()
    Dim lngIndex As Long, j As Long, i As Long
    Dim h1() As Double, h2() As Double, h3() As Double, h4() As Double, h5() As Double, h6() As String
    Dim hh1 As Double, hh2 As Double, hh3   As Double, hh4   As Double, hh5   As Double, hh6 As String

    
    lngIndex = 1
    
    Do While lngIndex < MSHFlexGrid1.Rows
        With MSHFlexGrid1
            If Len(Trim(.TextMatrix(lngIndex, 6))) <> 0 Then
                If .TextMatrix(lngIndex, 6) = .TextMatrix(lngIndex + 1, 6) Then
                    hh1 = hh1 + CLng(.TextMatrix(lngIndex, 1)) + CLng(.TextMatrix(lngIndex + 1, 1))
                    hh2 = hh2 + CDbl(.TextMatrix(lngIndex, 2)) + CDbl(.TextMatrix(lngIndex + 1, 2))
                    hh3 = hh3 + CDbl(.TextMatrix(lngIndex, 3)) + CDbl(.TextMatrix(lngIndex + 1, 3))
                    hh4 = hh4 + CDbl(.TextMatrix(lngIndex, 4)) + CDbl(.TextMatrix(lngIndex + 1, 4))
                    hh5 = hh5 + CDbl(.TextMatrix(lngIndex, 5)) + CDbl(.TextMatrix(lngIndex + 1, 5))
                    hh6 = .TextMatrix(lngIndex, 6)
                Else
                    j = j + 1
                    ReDim Preserve h1(j): ReDim Preserve h2(j): ReDim Preserve h3(j)
                    ReDim Preserve h4(j): ReDim Preserve h5(j): ReDim Preserve h6(j)
                    If hh6 = "" Then
                        h1(j) = .TextMatrix(lngIndex, 1): h2(j) = .TextMatrix(lngIndex, 2)
                        h3(j) = .TextMatrix(lngIndex, 3): h4(j) = .TextMatrix(lngIndex, 4)
                        h5(j) = .TextMatrix(lngIndex, 5): h6(j) = .TextMatrix(lngIndex, 6)
                    Else
                        h1(j) = hh1: h2(j) = hh2: h3(j) = hh3
                        h4(j) = hh4: h5(j) = hh5: h6(j) = hh6
                    End If
                    hh1 = 0: hh2 = 0: hh3 = 0: hh4 = 0: hh5 = 0: hh6 = ""
                End If
            End If
        End With
        lngIndex = lngIndex + 1
    Loop
    
    For i = 1 To MSHFlexGrid1.Rows - 1
        MSHFlexGrid1.TextMatrix(i, 1) = "": MSHFlexGrid1.TextMatrix(i, 2) = ""
        MSHFlexGrid1.TextMatrix(i, 3) = "": MSHFlexGrid1.TextMatrix(i, 4) = ""
        MSHFlexGrid1.TextMatrix(i, 5) = "": MSHFlexGrid1.TextMatrix(i, 6) = ""
    Next i
        
    For i = 1 To UBound(h1)
        With MSHFlexGrid1
            .TextMatrix(i, 1) = h1(i): .TextMatrix(i, 2) = h2(i)
            .TextMatrix(i, 3) = h3(i): .TextMatrix(i, 4) = h4(i)
            .TextMatrix(i, 5) = h5(i): .TextMatrix(i, 6) = h6(i)
        End With
    Next i
    
    
    
End Sub

Private Sub Form_Load()
   Dim i As Long, j As Long, Rw As Long, Cl As Long
    MSHFlexGrid1.Cols = 7
    MSHFlexGrid1.Rows = 8
    
    MSHFlexGrid1.TextMatrix(0, 1) = "Report COunt"
    MSHFlexGrid1.TextMatrix(0, 2) = "header2"
    MSHFlexGrid1.TextMatrix(0, 3) = "header3"
    MSHFlexGrid1.TextMatrix(0, 4) = "header4"
    MSHFlexGrid1.TextMatrix(0, 5) = "header5"
    MSHFlexGrid1.TextMatrix(0, 6) = "Date"
    
    MSHFlexGrid1.TextMatrix(1, 1) = 156
    MSHFlexGrid1.TextMatrix(1, 2) = 4465.85
    MSHFlexGrid1.TextMatrix(1, 3) = 491.2435
    MSHFlexGrid1.TextMatrix(1, 4) = 284.41
    MSHFlexGrid1.TextMatrix(1, 5) = 34.1292
    MSHFlexGrid1.TextMatrix(1, 6) = "1/1/2011"
    
    MSHFlexGrid1.TextMatrix(2, 1) = 1
    MSHFlexGrid1.TextMatrix(2, 2) = 2
    MSHFlexGrid1.TextMatrix(2, 3) = 3
    MSHFlexGrid1.TextMatrix(2, 4) = 4
    MSHFlexGrid1.TextMatrix(2, 5) = 5
    MSHFlexGrid1.TextMatrix(2, 6) = "2/1/2011"
    
    MSHFlexGrid1.TextMatrix(3, 1) = 1
    MSHFlexGrid1.TextMatrix(3, 2) = 1
    MSHFlexGrid1.TextMatrix(3, 3) = 1
    MSHFlexGrid1.TextMatrix(3, 4) = 1
    MSHFlexGrid1.TextMatrix(3, 5) = 1
    MSHFlexGrid1.TextMatrix(3, 6) = "3/1/2011"

    MSHFlexGrid1.TextMatrix(4, 1) = 1
    MSHFlexGrid1.TextMatrix(4, 2) = 1
    MSHFlexGrid1.TextMatrix(4, 3) = 1
    MSHFlexGrid1.TextMatrix(4, 4) = 1
    MSHFlexGrid1.TextMatrix(4, 5) = 1
    MSHFlexGrid1.TextMatrix(4, 6) = "3/1/2011"
    
    MSHFlexGrid1.TextMatrix(5, 1) = 1
    MSHFlexGrid1.TextMatrix(5, 2) = 1
    MSHFlexGrid1.TextMatrix(5, 3) = 1
    MSHFlexGrid1.TextMatrix(5, 4) = 1
    MSHFlexGrid1.TextMatrix(5, 5) = 1
    MSHFlexGrid1.TextMatrix(5, 6) = "3/1/2011"

    MSHFlexGrid1.TextMatrix(6, 1) = 1
    MSHFlexGrid1.TextMatrix(6, 2) = 1
    MSHFlexGrid1.TextMatrix(6, 3) = 1
    MSHFlexGrid1.TextMatrix(6, 4) = 1
    MSHFlexGrid1.TextMatrix(6, 5) = 1
    MSHFlexGrid1.TextMatrix(6, 6) = "3/1/2011"
End Sub