Forum

Adding invoices per...
 
Notifications
Clear all

Adding invoices per vendor id

13 Posts
2 Users
0 Reactions
75 Views
(@josros60)
Posts: 47
Trusted Member
Topic starter
 

Hi, 

 

Have the code works great with the help from forums.

 

One more thing would like to do  if possible some vendors have few invoices how can add to the code to add amounts per vendor I'd and display total.

 

 

 

Here is the code;

Sub ImportRawData()

 

    Dim c As Long

    Dim Col As Variant

    Dim Filename As String

    Dim Filepath As Variant

    Dim rngBeg As Range

    Dim rngEnd As Range

    Dim rngDst As Range

    Dim rngSrc As Range

    Dim rowsize As Long

    Dim wkbDst As Workbook

    Dim wkbSrc As Workbook

    Dim vFile

    

    vFile = Application.GetOpenFilename("CSV Files(*.csv),*.csv", , "please select a file", MultiSelect:=False)

    

    

        Set wkbDst = ThisWorkbook

        Set rngDst = wkbDst.Worksheets("EFT Summary").Range("A5:H5")

        

        Filepath = "C:Usersjose.rossiDesktopNCL EFT_Summary.xlsm"

        Filename = "apcbtclz.csv"

        

        On Error Resume Next

            Set wkbSrc = Workbooks(Filename)

            If Err = 9 Then

                If Filepath <> "" Then ChDir Filepath Else ChDir ThisWorkbook.Path

                'Filename = Application.GetOpenFilename("Excel Workbooks, *.xlsx")

                If Filename = "False" Then Exit Sub

                Set wkbSrc = Workbooks.Open(Filename)

            End If

        On Error GoTo 0

        

        ' Clear previous data.

        'rngDst.Resize(rngDst.Parent.UsedRange.Rows.Count).ClearContents

        

        ' Import the data.

        With wkbSrc.Worksheets("apcbtclz").UsedRange

            ' Step through the source data columns.

            For Each Col In Array("AW", "BO", "BB", "AX", "X", "CH")

            

                        

            

            

            

                ' Data starts on row 1.

                Set rngBeg = .Parent.Cells(1, Col)

                

                ' Find the row where the data ends in this column.

                Set rngEnd = .Parent.Cells(Rows.Count, Col).End(xlUp)

                

                ' Number of rows in this column.

                rowsize = rngEnd.Row '- rngBeg.Row

                

                If rowsize > 0 Then

                    Set rngSrc = .Parent.Range(rngBeg, rngEnd)

                    rngDst.Offset(0, c).Resize(rowsize, 1).Value = rngSrc.Value

                End If

                

                ' Increment the column offset.

                c = c + 1

                

                If c = 6 Then Let c = 7

            Next Col

            

        End With

        

End Sub

 

Thank

 
Posted : 15/10/2021 2:25 am
(@catalinb)
Posts: 1937
Member Admin
 

Hi Jose,

Hard to see your data structure without sample files, so I'll provide a theoretical solution: Use a dictionary to store the values by ID, if the ID already exists add the current value to the stored value:

dim Dict as Object: Set Dict=CreateObject("scripting.dictionary")

Dim ID as string, OldVal as Double, CurrentVal as double

For i=1 to 100

ID=SourceWb.Worksheets(1).Cells(i,"A").Value

CurrentVal=SourceWb.Worksheets(1).Cells(i,"B").Value

OldVal=0

If Dict.Exists(ID)=True then OldVal=Dict(ID)

Dict(ID)=OldVal+CurrentVal

Next i

In Excel you have better alternatives to read that csv, why don't you use Power Query to update data from that csv into the xlsm file?

 
Posted : 16/10/2021 1:21 am
(@josros60)
Posts: 47
Trusted Member
Topic starter
 

Hi Catalin,

 

couldn't figure out where to put the code in the existing that I posted #1, attaching a sample of workbook.

 

 

Thank you,

 
Posted : 16/10/2021 6:13 pm
(@catalinb)
Posts: 1937
Member Admin
 

In Excel you have better alternatives to read that csv, why don't you use Power Query to update data from that csv into the xlsm file?

 
Posted : 16/10/2021 11:24 pm
(@josros60)
Posts: 47
Trusted Member
Topic starter
 

Thank you Catalina for responding but don't know how to use power query.

Any suggestions how to?

 

Thanks again.

 
Posted : 17/10/2021 10:25 am
(@josros60)
Posts: 47
Trusted Member
Topic starter
 

My apologies for wrong spelling your name.

 
Posted : 17/10/2021 10:26 am
(@catalinb)
Posts: 1937
Member Admin
 

What office version are you using?

 
Posted : 17/10/2021 12:50 pm
(@josros60)
Posts: 47
Trusted Member
Topic starter
 

0ffice 365 

 

Think 2016

 
Posted : 17/10/2021 1:10 pm
(@josros60)
Posts: 47
Trusted Member
Topic starter
 

Any suggestions?

 

Thank you.

 
Posted : 18/10/2021 10:30 pm
(@catalinb)
Posts: 1937
Member Admin
 

Can you provide a sample csv file as well? The structure of that file is really important in processing, no matter if it will be power query or vba.

 
Posted : 18/10/2021 10:40 pm
(@josros60)
Posts: 47
Trusted Member
Topic starter
 

Hi Catalin,

 

attached sample file.

 

Thank you,

 
Posted : 19/10/2021 11:13 am
(@catalinb)
Posts: 1937
Member Admin
 

Here is an example of summing data with power query.

I Grouped data by column 122 as ID, aggregating columns 123 and 125. (have no idea which are the columns you want, as the csv structure don't match what you have in code, some are empty:  Array("AW", "BO", "BB", "AX", "X", "CH"))

Summing values might be wrong, I noticed that some are in CAD, some in USD, was not able to identify if there is a column with amounts converted to the same currency, therefore adding values in different currencies is wrong.

 
Posted : 19/10/2021 9:06 pm
(@josros60)
Posts: 47
Trusted Member
Topic starter
 

Thank you very much for all your help Catalin.

 
Posted : 19/10/2021 11:42 pm
Share: