Results 1 to 4 of 4

adding up rows of text/numbers that are exact matchs

Threaded View

  1. #1
    Registered User
    Join Date
    06-04-2009
    Location
    Edmonton, Alberta, Canada
    MS-Off Ver
    Excel 2003
    Posts
    2

    adding up rows of text/numbers that are exact matchs

    Looking for some help with my code for adding up rows of cells of text mixed with numbers, each row would look like

    b1 2 30 10 7/8 Gables 3/4 Pref Birch
    b2 2 30 10 7/8 Gables 3/4 Pref Birch
    b3 2 30 10 7/8 Gables 3/4 Pref Birch
    b4 2 30 10 7/8 Gables 3/4 Pref Birch
    b1 1 38 1/2 10 7/8 Base 3/4 Pref Birch
    b2 1 38 1/2 10 7/8 Base 3/4 Pref Birch
    b3 1 38 1/2 10 7/8 Base 3/4 Pref Birch
    b4 1 28 1/2 10 7/8 Base 3/4 Pref Birch

    and i would like to make them add up to look like this

    b1, b2, b3, b4 8 30 10 7/8 Gables 3/4 Pref Birch
    b1, b2, b3 3 38 1/2 10 7/8 Base 3/4 Pref Birch
    b4 1 38 1/2 10 7/8 Base 3/4 Pref Birch

    code i have currently is:

    Sub Compile()
    
    Dim Sep As String
    Dim Pagename As String
    Dim WholeLine As String
    Dim WholeLine2 As String
    Dim LastWholeLine As String
    Dim NextWholeLine As String
    Dim NewWholeline As String
    Dim FNum As Integer
    Dim RowNdx As Long
    Dim ColNdx As Integer
    Dim ColNdx2 As Integer
    Dim StartRow As Long
    Dim EndRow As Long
    Dim StartCol As Integer
    Dim StartCol2 As Integer
    Dim EndCol As Integer
    Dim EndCol2 As Integer
    Dim CellValue As String
    Dim Count As Integer
    
    Dim RowNdx2 As Long
    Dim StartRow2 As Long
    Dim EndRow2 As Long
    Dim CellValue2 As String
    Dim TempNum As Integer
    Dim TempLine As String
    
    Sep = "|"
    StartRow = 13
    StartCol = 16
    StartCol2 = 16
    EndCol = 22
    EndCol2 = 22
    
    StartRow2 = 13
    EndRow2 = 300
    
    YesNo = MsgBox("Are you sure?", vbYesNo, "Saving File")
    Select Case YesNo
    Case vbYes
    For RowNdx2 = StartRow2 To EndRow2
        CellValue2 = Cells(RowNdx2, 16).Text
        If CellValue2 = "" Then
        RowNdx2 = RowNdx2 - 1
        EndRow = RowNdx2
        GoTo skip1
        End If
    Next RowNdx2
    skip1:
           
    Pagename = Range("c31") + Range("c30") & ".txt" ' location and name of saved file
    
    Open Pagename For Output As #1
    
    For RowNdx = StartRow + Count To EndRow
        Cells(45 + RowNdx, 1).Value = RowNdx
        Cells(45 + RowNdx, 3).Value = Count
        
        Count = 0
        WholeLine = ""
        NextWholeLine = ""
        
        For ColNdx = StartCol To EndCol
            If Cells(RowNdx, ColNdx).Value = "" Then
                CellValue = Chr(34) & Chr(34)
            Else
               CellValue = Cells(RowNdx, ColNdx).Text
            End If
            WholeLine = WholeLine & CellValue & Sep
        Next ColNdx
        
        LastWholeLine = Mid(WholeLine, InStr(1, WholeLine, Sep) + 1, Len(WholeLine))
           
        For RowNdx2 = StartRow + 1 To EndRow
            Cells(45 + RowNdx2, 2).Value = RowNdx2
            WholeLine2 = ""
            
            For ColNdx2 = StartCol2 To EndCol2
                If Cells(RowNdx2, ColNdx2).Value = "" Then
                    Close #1
                    GoTo skip2
             Else
                   CellValue = Cells(RowNdx2, ColNdx2).Text
                End If
                WholeLine2 = WholeLine2 & CellValue & Sep
            Next ColNdx2
            
            NextWholeLine = Mid(WholeLine2, InStr(1, WholeLine2, Sep) + 1, Len(WholeLine2))
                    
            If LastWholeLine = NextWholeLine Then
                Count = Count + 1
                If NewWholeline = "" Then
                    TempNum = Val(Left(LastWholeLine, InStr(1, LastWholeLine, Sep) - 1)) + Val(Left(NextWholeLine, InStr(1, NextWholeLine, Sep) - 1))
                    NewWholeline = Left(WholeLine, InStr(1, WholeLine, Sep) - 1) + "," + Left(WholeLine2, InStr(1, WholeLine2, Sep) - 1) + Sep + Str(TempNum) + Sep + Mid(NextWholeLine, InStr(1, NextWholeLine, Sep) + 1, Len(NextWholeLine))
                Else
                    TempLine = Mid(NewWholeline, InStr(1, NewWholeline, Sep) + 1, Len(NewWholeline))
                    TempNum = Val(Left(TempLine, InStr(1, TempLine, Sep) - 1)) + Val(Left(NextWholeLine, InStr(1, NextWholeLine, Sep) - 1))
                    NewWholeline = Left(NewWholeline, InStr(1, NewWholeline, Sep) - 1) + "," + Left(WholeLine2, InStr(1, WholeLine2, Sep) - 1) + Sep + Str(TempNum) + Sep + Mid(NextWholeLine, InStr(1, NextWholeLine, Sep) + 1, Len(NextWholeLine))
                End If
            End If
    
            Print #1, NewWholeline
                
            Next RowNdx2
        
        NewWholeline = ""
        
        Next RowNdx
        
    Close #1
    
    MsgBox ("Your file has been saved")
    Case vbNo
    GoTo skip2
    End Select
    
    skip2:
    
    Application.Run "refreshlist"
    
    End Sub

    any ideas ? also everything is stored in a .txt file for future use

    nevermind, figured it out myself
    Last edited by kerth; 06-08-2009 at 08:12 PM. Reason: posting a workbook

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

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

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1