October 25, 2017
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:\Users\jose.rossi\Desktop\NCL 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
Power Query
Power Pivot
Xtreme Pivot Tables
Excel for Decision Making
Excel for Finance
Excel Analysis Toolpak
Power BI
Excel
Word
Outlook
Excel Expert
Excel Customer Service
PowerPoint
November 8, 2013
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?
Power Query
Power Pivot
Xtreme Pivot Tables
Excel for Decision Making
Excel for Finance
Excel Analysis Toolpak
Power BI
Excel
Word
Outlook
Excel Expert
Excel Customer Service
PowerPoint
November 8, 2013
Power Query
Power Pivot
Xtreme Pivot Tables
Excel for Decision Making
Excel for Finance
Excel Analysis Toolpak
Power BI
Excel
Word
Outlook
Excel Expert
Excel Customer Service
PowerPoint
November 8, 2013
Power Query
Power Pivot
Xtreme Pivot Tables
Excel for Decision Making
Excel for Finance
Excel Analysis Toolpak
Power BI
Excel
Word
Outlook
Excel Expert
Excel Customer Service
PowerPoint
November 8, 2013
Power Query
Power Pivot
Xtreme Pivot Tables
Excel for Decision Making
Excel for Finance
Excel Analysis Toolpak
Power BI
Excel
Word
Outlook
Excel Expert
Excel Customer Service
PowerPoint
November 8, 2013
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.
1 Guest(s)