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
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?
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,
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?
Thank you Catalina for responding but don't know how to use power query.
Any suggestions how to?
Thanks again.
My apologies for wrong spelling your name.
What office version are you using?
0ffice 365
Think 2016
Any suggestions?
Thank you.
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.
Hi Catalin,
attached sample file.
Thank you,
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.
Thank you very much for all your help Catalin.