• Skip to main content
  • Skip to header right navigation
  • Skip to site footer

My Online Training Hub

Learn Dashboards, Excel, Power BI, Power Query, Power Pivot

  • Courses
  • Pricing
    • Free Courses
    • Power BI Course
    • Excel Power Query Course
    • Power Pivot and DAX Course
    • Excel Dashboard Course
    • Excel PivotTable Course – Quick Start
    • Advanced Excel Formulas Course
    • Excel Expert Advanced Excel Training
    • Excel Tables Course
    • Excel, Word, Outlook
    • Financial Modelling Course
    • Excel PivotTable Course
    • Excel for Customer Service Professionals
    • Excel for Operations Management Course
    • Excel for Decision Making Under Uncertainty Course
    • Excel for Finance Course
    • Excel Analysis ToolPak Course
    • Multi-User Pricing
  • Resources
    • Free Downloads
    • Excel Functions Explained
    • Excel Formulas
    • Excel Add-ins
    • IF Function
      • Excel IF Statement Explained
      • Excel IF AND OR Functions
      • IF Formula Builder
    • Time & Dates in Excel
      • Excel Date & Time
      • Calculating Time in Excel
      • Excel Time Calculation Tricks
      • Excel Date and Time Formatting
    • Excel Keyboard Shortcuts
    • Excel Custom Number Format Guide
    • Pivot Tables Guide
    • VLOOKUP Guide
    • ALT Codes
    • Excel VBA & Macros
    • Excel User Forms
    • VBA String Functions
  • Members
    • Login
    • Password Reset
  • Blog
  • Excel Webinars
  • Excel Forum
    • Register as Forum Member

Adding invoices per vendor id|VBA & Macros|Excel Forum|My Online Training Hub

You are here: Home / Adding invoices per vendor id|VBA & Macros|Excel Forum|My Online Training Hub
Avatar
sp_LogInOut Log In sp_Registration Register
sp_Search Search
Advanced Search|Last Search Results
Search
Forum Scope




Match



Forum Options



Minimum search word length is 3 characters - maximum search word length is 84 characters
sp_Search Search
sp_RankInfo
Lost password?
sp_CrumbsHome HomeExcel ForumVBA & MacrosAdding invoices per vendor id
sp_PrintTopic sp_TopicIcon
Adding invoices per vendor id
Avatar
Jose Zavala
Member
Members
Level 0
Forum Posts: 41
Member Since:
October 25, 2017
sp_UserOfflineSmall Offline
1
October 14, 2021 - 4:25 pm
sp_Permalink sp_Print

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

sp_AnswersTopicSeeAnswer See Answer
Avatar
Catalin Bombea
Iasi, Romania
Admin
Level 10
Forum Posts: 1807
Member Since:
November 8, 2013
sp_UserOfflineSmall Offline
2
October 15, 2021 - 3:21 pm
sp_Permalink sp_Print

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?

Avatar
Jose Zavala
Member
Members
Level 0
Forum Posts: 41
Member Since:
October 25, 2017
sp_UserOfflineSmall Offline
3
October 16, 2021 - 8:13 am
sp_Permalink sp_Print

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,

Avatar
Catalin Bombea
Iasi, Romania
Admin
Level 10
Forum Posts: 1807
Member Since:
November 8, 2013
sp_UserOfflineSmall Offline
4
October 16, 2021 - 1:24 pm
sp_Permalink sp_Print

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?

Avatar
Jose Zavala
Member
Members
Level 0
Forum Posts: 41
Member Since:
October 25, 2017
sp_UserOfflineSmall Offline
5
October 17, 2021 - 12:25 am
sp_Permalink sp_Print

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

Any suggestions how to?

 

Thanks again.

Avatar
Jose Zavala
Member
Members
Level 0
Forum Posts: 41
Member Since:
October 25, 2017
sp_UserOfflineSmall Offline
6
October 17, 2021 - 12:26 am
sp_Permalink sp_Print

My apologies for wrong spelling your name.

Avatar
Catalin Bombea
Iasi, Romania
Admin
Level 10
Forum Posts: 1807
Member Since:
November 8, 2013
sp_UserOfflineSmall Offline
7
October 17, 2021 - 2:50 am
sp_Permalink sp_Print

What office version are you using?

Avatar
Jose Zavala
Member
Members
Level 0
Forum Posts: 41
Member Since:
October 25, 2017
sp_UserOfflineSmall Offline
8
October 17, 2021 - 3:10 am
sp_Permalink sp_Print

0ffice 365 

 

Think 2016

Avatar
Jose Zavala
Member
Members
Level 0
Forum Posts: 41
Member Since:
October 25, 2017
sp_UserOfflineSmall Offline
9
October 18, 2021 - 12:30 pm
sp_Permalink sp_Print

Any suggestions?

 

Thank you.

Avatar
Catalin Bombea
Iasi, Romania
Admin
Level 10
Forum Posts: 1807
Member Since:
November 8, 2013
sp_UserOfflineSmall Offline
10
October 18, 2021 - 12:40 pm
sp_Permalink sp_Print

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.

Avatar
Jose Zavala
Member
Members
Level 0
Forum Posts: 41
Member Since:
October 25, 2017
sp_UserOfflineSmall Offline
11
October 19, 2021 - 1:13 am
sp_Permalink sp_Print

Hi Catalin,

 

attached sample file.

 

Thank you,

Avatar
Catalin Bombea
Iasi, Romania
Admin
Level 10
Forum Posts: 1807
Member Since:
November 8, 2013
sp_UserOfflineSmall Offline
12
October 19, 2021 - 11:06 am
sp_Permalink sp_Print sp_EditHistory

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.

Avatar
Jose Zavala
Member
Members
Level 0
Forum Posts: 41
Member Since:
October 25, 2017
sp_UserOfflineSmall Offline
13
October 19, 2021 - 1:42 pm
sp_Permalink sp_Print

Thank you very much for all your help Catalin.

sp_AnswersTopicAnswer
Answers Post
sp_Feed
Go to top
Forum Timezone: Australia/Brisbane
Most Users Ever Online: 245
Currently Online: Chandler Davis, Ramon Lagos, michael serna
Guest(s) 9
Currently Browsing this Page:
1 Guest(s)
Top Posters:
SunnyKow: 1432
Anders Sehlstedt: 870
Purfleet: 412
Frans Visser: 346
David_Ng: 306
lea cohen: 219
A.Maurizio: 202
Jessica Stewart: 202
Aye Mu: 201
jaryszek: 183
Newest Members:
michael serna
mashal sana
Tiffany Kang
Leah Gillmore
Sopi Yuniarti
LAFONSO HERNANDEZ
Hayden Hao
Angela chen
Sean Moore
John Chisholm
Forum Stats:
Groups: 3
Forums: 24
Topics: 6215
Posts: 27245

 

Member Stats:
Guest Posters: 49
Members: 31897
Moderators: 3
Admins: 4
Administrators: Mynda Treacy, Philip Treacy, Catalin Bombea, FT
Moderators: MOTH Support, Velouria, Riny van Eekelen
© Simple:Press —sp_Information

Sidebar

Blog Categories

  • Excel
  • Excel Charts
  • Excel Dashboard
  • Excel Formulas
  • Excel PivotTables
  • Excel Shortcuts
  • Excel VBA
  • General Tips
  • Online Training
  • Outlook
  • Power Apps
  • Power Automate
  • Power BI
  • Power Pivot
  • Power Query
microsoft mvp logo
trustpilot excellent rating
Secured by Sucuri Badge
MyOnlineTrainingHub on YouTube Mynda Treacy on Linked In Mynda Treacy on Instagram Mynda Treacy on Twitter Mynda Treacy on Pinterest MyOnlineTrainingHub on Facebook
 

Company

  • About My Online Training Hub
  • Disclosure Statement
  • Frequently Asked Questions
  • Guarantee
  • Privacy Policy
  • Terms & Conditions
  • Testimonials
  • Become an Affiliate

Support

  • Contact
  • Forum
  • Helpdesk - For Technical Issues

Copyright © 2023 · My Online Training Hub · All Rights Reserved. Microsoft and the Microsoft Office logo are trademarks or registered trademarks of Microsoft Corporation in the United States and/or other countries. Product names, logos, brands, and other trademarks featured or referred to within this website are the property of their respective trademark holders.