SOLVED
Home

Put multiple fields from various excel invoices into 1 spreadsheet

%3CLINGO-SUB%20id%3D%22lingo-sub-820930%22%20slang%3D%22en-US%22%3EPut%20multiple%20fields%20from%20various%20excel%20invoices%20into%201%20spreadsheet%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-820930%22%20slang%3D%22en-US%22%3E%3CP%3EI%20use%20Excel%20(Office%20365)%20to%20create%20invoices%2C%20and%20I%20wanted%20to%20see%20if%20it's%20possible%20to%20take%20all%20invoice%20files%20I%20have%20and%20create%201%20spreadsheet%20that%20has%20everything%20listed.%20Basically%20I%20want%20to%20consolidate%20all%20my%20customers%20into%201%20list.%20I%20believe%20all%20my%20customer%20data%20is%20consistently%20in%20the%20same%20Column%2FRow%20per%20each%20invoice%2C%20although%20the%20Items%2FDescription%20lines%20change.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3ESee%20attached%20photos%20below%20for%20my%20invoice%20example%2C%20and%20the%20end%20result%20I%20would%20like%20to%20achieve.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-inline%22%20style%3D%22width%3A%20999px%3B%22%3E%3CIMG%20src%3D%22https%3A%2F%2Fgxcuf89792.i.lithium.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F128321i8C2D9AA5AD65A1C9%2Fimage-size%2Flarge%3Fv%3D1.0%26amp%3Bpx%3D999%22%20alt%3D%22ExampleInvoice.jpg%22%20title%3D%22ExampleInvoice.jpg%22%20%2F%3E%3C%2FSPAN%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-inline%22%20style%3D%22width%3A%20999px%3B%22%3E%3CIMG%20src%3D%22https%3A%2F%2Fgxcuf89792.i.lithium.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F128322i91E351B23B6291A3%2Fimage-size%2Flarge%3Fv%3D1.0%26amp%3Bpx%3D999%22%20alt%3D%22EndResult_example.jpg%22%20title%3D%22EndResult_example.jpg%22%20%2F%3E%3C%2FSPAN%3E%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-LABS%20id%3D%22lingo-labs-820930%22%20slang%3D%22en-US%22%3E%3CLINGO-LABEL%3EExcel%3C%2FLINGO-LABEL%3E%3CLINGO-LABEL%3EFormulas%20and%20Functions%3C%2FLINGO-LABEL%3E%3CLINGO-LABEL%3EMacros%20and%20VBA%3C%2FLINGO-LABEL%3E%3CLINGO-LABEL%3EPower%20BI%3C%2FLINGO-LABEL%3E%3C%2FLINGO-LABS%3E%3CLINGO-SUB%20id%3D%22lingo-sub-821034%22%20slang%3D%22en-US%22%3ERe%3A%20Put%20multiple%20fields%20from%20various%20excel%20invoices%20into%201%20spreadsheet%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-821034%22%20slang%3D%22en-US%22%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F397625%22%20target%3D%22_blank%22%3E%40RogPos%3C%2FA%3E%26nbsp%3B%3C%2FP%3E%3CP%3EThat's%20doable%20with%20VBA%20provided%20you%20give%20us%20more%20details%20about%20the%20layout%20of%20the%20Invoice%20Sheet.%20Why%20not%20upload%20a%20sample%20invoice%20sheet%20with%20some%20dummy%20data%20in%20it%20with%20the%20same%20layout%3F%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-821118%22%20slang%3D%22en-US%22%3ERe%3A%20Put%20multiple%20fields%20from%20various%20excel%20invoices%20into%201%20spreadsheet%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-821118%22%20slang%3D%22en-US%22%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F394231%22%20target%3D%22_blank%22%3E%40Subodh_Tiwari_sktneer%3C%2FA%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EI%20attached%204%20sample%20invoices%20that%20represent%20my%20usual%20invoice%20layouts.%3C%2FP%3E%3CP%3EI%20tried%20using%20Power%20Query%2C%20but%20I'm%20not%20familiar%20with%20how%20to%20use%20it%20properly%20and%20the%20results%20were%20listed%20all%20over%20the%20place%2C%20so%20VBA%20sounds%20promising.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EThank%20you!%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-821213%22%20slang%3D%22en-US%22%3ERe%3A%20Put%20multiple%20fields%20from%20various%20excel%20invoices%20into%201%20spreadsheet%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-821213%22%20slang%3D%22en-US%22%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F397625%22%20target%3D%22_blank%22%3E%40RogPos%3C%2FA%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EYou%20uploaded%20invoices%20without%20any%20dummy%20data%2C%20never%20mind.%3C%2FP%3E%3CP%3EWhere%20exactly%20you%20will%20enter%20the%20Invoice%23%3F%3C%2FP%3E%3CP%3EIs%20it%20possible%20for%20you%20to%20upload%20one%20invoice%20with%20some%20dummy%20data%20only%20in%20the%20fields%20which%20are%20to%20be%20fetched%20into%20Master%20Invoice%20File%3F%3C%2FP%3E%3CP%3EBtw%20I%20saw%20that%20you%20have%20created%20the%20Named%20Ranges%20on%20invoice%20sheet%2C%20that's%20a%20good%20idea%20but%20at%20the%20same%20time%20names%20of%20the%20named%20ranges%20are%20not%20meaningful.%20You%20could%20name%20them%20like%20_Invoice%2C%20_CompanyName%2C%20_Address%20etc.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EFew%20queries...%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E1)%20When%20a%20Master%20Invoice%20Workbook%20is%20created%20with%20details%20of%20all%20the%20invoices%2C%20how%20would%20you%20like%20to%20name%20it%3F%20Will%20it%20be%20a%20new%20Master%20Invoice%20with%20a%20datetime%20stamp%20in%20the%20file%20name%20each%20time%20you%20run%20the%20code.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E2)%20If%20the%20above%20assumption%20is%20not%20correct%2C%20would%20you%20always%20like%20to%20have%20one%20Master%20Invoice%20File%20and%26nbsp%3B%20delete%20any%20existing%20data%20in%20previously%20Existing%20Master%20Invoice%20file%20and%20then%20append%20data%20from%20all%20the%20invoices%3F%20Or%20once%20you%20run%20the%20code%2C%20all%20the%20invoices%20which%20are%20processed%20by%20the%20code%20should%20be%20moved%20to%20another%20sub-folder%20(say%20Consolidated%20Invoices%20in%20the%20same%20directory)%20so%20that%20you%20don't%20duplicate%20the%20data%20in%20the%20Master%20Invoice%20File%20while%20running%20the%20code%20next%20time%3F%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E3)%20I%20assume%20that%20all%20the%20invoices%20are%20saved%20in%20the%20same%20folder.%20Can%20I%20also%20assume%20that%20names%20of%20all%20the%20invoice%20files%20start%20with%20a%20%3CSTRONG%3E%23%3C%2FSTRONG%3Esign%20i.e.%20%3CSTRONG%3E%23%3C%2FSTRONG%3E1000_CompanyA-Project1.xls%20etc.%3F%20I%20am%20asking%20this%20as%20code%20needs%20way%20to%20differentiate%20between%20an%20Invoice%20file%20and%20other%20files%20if%20files%20other%20than%20invoice%20files%20are%20also%20saved%20in%20the%20same%20folder.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E4)%20Will%20all%20the%20invoice%20files%20always%20have%20the%20%3CSTRONG%3E.xls%3C%2FSTRONG%3Efile%20extension%3F%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E5)%20Is%20it%20okay%20if%20the%20code%20opens%20a%20Folder%20Picker%20Dialog%20Window%20for%20you%20to%20choose%20the%20source%20folder%20where%20all%20the%20invoice%20files%20are%20saved%3F%20Or%20it%20is%20always%20a%20fixed%20folder%3F%20If%20yes%2C%20what's%20the%20full%20path%20of%20the%20source%20folder%3F%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-821276%22%20slang%3D%22en-US%22%3ERe%3A%20Put%20multiple%20fields%20from%20various%20excel%20invoices%20into%201%20spreadsheet%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-821276%22%20slang%3D%22en-US%22%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F394231%22%20target%3D%22_blank%22%3E%40Subodh_Tiwari_sktneer%3C%2FA%3E%26nbsp%3B%3C%2FP%3E%3COL%3E%3CLI%3E%3CP%3E%3CSTRONG%3EYou%20uploaded%20invoices%20without%20any%20dummy%20data%2C%20never%20mind%3C%2FSTRONG%3E.%3C%2FP%3EAll%20the%20invoices%20I%20uploaded%20should%20have%20dummy%20data%20in%20the%20%22Invoice%22%20worksheet.%20I%20just%20randomly%20entered%20values%20that%20match%20how%20my%20layout%20is.%20Unless%20I%20don't%20understand%20what%20you%20mean%20by%20dummy%20data%3F%3C%2FLI%3E%3CLI%3E%3CP%3E%3CSTRONG%3EWhere%20exactly%20you%20will%20enter%20the%20Invoice%23%3F%3C%2FSTRONG%3E%3C%2FP%3EI%20enter%20it%20directly%20in%20the%20field%20next%20to%20%22Invoice%20No.%22%20I%20believe%20the%20field%20is%20named%20NO.%3C%2FLI%3E%3CLI%3E%3CP%3E%3CSTRONG%3EIs%20it%20possible%20for%20you%20to%20upload%20one%20invoice%20with%20some%20dummy%20data%20only%20in%20the%20fields%20which%20are%20to%20be%20fetched%20into%20Master%20Invoice%20File%3F%3C%2FSTRONG%3E%3C%2FP%3EAt%20bare%20minimum%20it%20would%20just%20be%20the%20%22Customer%22%20info%3A%20Name%2C%20Address%2C%20City%2C%20State%2C%20Zip%2C%20Phone%2C%20and%20the%20Invoice%20Number.%20(I'm%20not%20sure%20if%20it's%20possible%20to%20put%20in%20the%20Qty%2C%20Description%2C%20Unit%20Price%20since%20the%20locations%20vary%20with%20each%20invoice%20and%20they%20are%20multiple%20lines.%20It%20would%20be%20nice%2C%20but%20looks%20too%20complicated.)%20I'm%20only%20using%20information%20from%20the%20%22Invoice%22%20worksheet%2C%20not%20the%20%22customize%22%20one.%20For%20example%3A%3CBR%20%2F%3E%3CTABLE%20border%3D%221%22%3E%3CTBODY%3E%3CTR%3E%3CTD%3EName%3C%2FTD%3E%3CTD%3EAddress%3C%2FTD%3E%3CTD%3ECity%3C%2FTD%3E%3CTD%3EState%3C%2FTD%3E%3CTD%3EZip%3C%2FTD%3E%3CTD%3EPhone%3C%2FTD%3E%3CTD%3EInvoice%20No%3C%2FTD%3E%3C%2FTR%3E%3CTR%3E%3CTD%3ECompany%20A%3C%2FTD%3E%3CTD%3EAddress%20A%3C%2FTD%3E%3CTD%3ECity%20A%3C%2FTD%3E%3CTD%3EState%20A%3C%2FTD%3E%3CTD%3EZip%20A%3C%2FTD%3E%3CTD%3EPhone%20A%3C%2FTD%3E%3CTD%3E1000%3C%2FTD%3E%3C%2FTR%3E%3CTR%3E%3CTD%3ECompany%20B%3C%2FTD%3E%3CTD%3EAddress%20B%3C%2FTD%3E%3CTD%3ECity%20B%3C%2FTD%3E%3CTD%3EState%20B%3C%2FTD%3E%3CTD%3EZip%20B%3C%2FTD%3E%3CTD%3EPhone%20B%3C%2FTD%3E%3CTD%3E1001%3C%2FTD%3E%3C%2FTR%3E%3C%2FTBODY%3E%3C%2FTABLE%3E%3C%2FLI%3E%3CLI%3E%3CP%3E%3CSTRONG%3EBtw%20I%20saw%20that%20you%20have%20created%20the%20Named%20Ranges%20on%20invoice%20sheet%2C%20that's%20a%20good%20idea%20but%20at%20the%20same%20time%20names%20of%20the%20named%20ranges%20are%20not%20meaningful.%20You%20could%20name%20them%20like%20_Invoice%2C%20_CompanyName%2C%20_Address%20etc.%3C%2FSTRONG%3E%3C%2FP%3EI%20actually%20didn't%20create%20the%20template%2Fworksheets%2C%20someone%20else%20did%20a%20long%20time%20ago.%20But%20I%20agree%20with%20you%2C%20the%20naming%20isn't%20good.%3C%2FLI%3E%3C%2FOL%3E%3CP%3E%3CSTRONG%3E1)%20When%20a%20Master%20Invoice%20Workbook%20is%20created%20with%20details%20of%20all%20the%20invoices%2C%20how%20would%20you%20like%20to%20name%20it%3F%20Will%20it%20be%20a%20new%20Master%20Invoice%20with%20a%20datetime%20stamp%20in%20the%20file%20name%20each%20time%20you%20run%20the%20code.%3C%2FSTRONG%3E%3C%2FP%3E%3CP%3ENamed%20after%20the%20folder%20that%20the%20invoices%20are%20in%20%2B%20datetime%20stamp%20I%20was%20thinking.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%3CSTRONG%3E2)%20If%20the%20above%20assumption%20is%20not%20correct%2C%20would%20you%20always%20like%20to%20have%20one%20Master%20Invoice%20File%20and%26nbsp%3B%20delete%20any%20existing%20data%20in%20previously%20Existing%20Master%20Invoice%20file%20and%20then%20append%20data%20from%20all%20the%20invoices%3F%20Or%20once%20you%20run%20the%20code%2C%20all%20the%20invoices%20which%20are%20processed%20by%20the%20code%20should%20be%20moved%20to%20another%20sub-folder%20(say%20Consolidated%20Invoices%20in%20the%20same%20directory)%20so%20that%20you%20don't%20duplicate%20the%20data%20in%20the%20Master%20Invoice%20File%20while%20running%20the%20code%20next%20time%3F%3C%2FSTRONG%3E%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EI%20like%20the%20idea%20of%20moving%20to%20a%20sub-folder%20so%20I%20don't%20have%20duplicate%20data%2C%20but%20I%20don't%20know%20if%20that%20will%20be%20good%20in%20practice%2C%20unless%20it's%20easy%20for%20me%20to%20disable%20those%20lines%20of%20code%20if%20needed%3F%20But%20just%20saving%20everything%20with%20the%20folder%20name%20%2B%20datetime%20stamp%20is%20fine.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%3CSTRONG%3E3)%20I%20assume%20that%20all%20the%20invoices%20are%20saved%20in%20the%20same%20folder.%20Can%20I%20also%20assume%20that%20names%20of%20all%20the%20invoice%20files%20start%20with%20a%20%23sign%20i.e.%20%231000_CompanyA-Project1.xls%20etc.%3F%20I%20am%20asking%20this%20as%20code%20needs%20way%20to%20differentiate%20between%20an%20Invoice%20file%20and%20other%20files%20if%20files%20other%20than%20invoice%20files%20are%20also%20saved%20in%20the%20same%20folder.%3C%2FSTRONG%3E%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EThey%20are%20all%20in%20the%20same%20main%20folder(s)%20with%20some%20having%20subfolders.%3C%2FP%3E%3CP%3EThey%20all%20start%20that%20same%20way%3A%20%23%20followed%20by%20invoice%20number%20and%20underscore.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%3CSTRONG%3E4)%20Will%20all%20the%20invoice%20files%20always%20have%20the%20.xlsfile%20extension%3F%3C%2FSTRONG%3E%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3Exls%20or%20xlsx%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%3CSTRONG%3E5)%20Is%20it%20okay%20if%20the%20code%20opens%20a%20Folder%20Picker%20Dialog%20Window%20for%20you%20to%20choose%20the%20source%20folder%20where%20all%20the%20invoice%20files%20are%20saved%3F%20Or%20it%20is%20always%20a%20fixed%20folder%3F%20If%20yes%2C%20what's%20the%20full%20path%20of%20the%20source%20folder%3F%3C%2FSTRONG%3E%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EFolder%20Picker%20Dialog%20Window%20is%20fine%20since%20I%20have%20different%20folders%20I%20need%20to%20run%20it%20in.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-821341%22%20slang%3D%22en-US%22%3ERe%3A%20Put%20multiple%20fields%20from%20various%20excel%20invoices%20into%201%20spreadsheet%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-821341%22%20slang%3D%22en-US%22%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F397625%22%20target%3D%22_blank%22%3E%40RogPos%3C%2FA%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EPlease%20find%20the%20attached%20with%20a%20code%20called%20%22CombineAllInvoices%22%20on%20m_CombineAllInvoices%20Module.%3C%2FP%3E%3CP%3EThe%20file%20has%20a%20hidden%20sheet%20called%20Template%20in%20it%20with%20the%20headers%20only.%3C%2FP%3E%3CP%3EYou%20will%20also%20find%20a%20button%20called%20%22Combine%20All%20Invoices%22%20on%20Main%20Sheet%20and%20you%20may%20click%20this%20button%20to%20run%20the%20code.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EHere%20is%20the%20code....%3C%2FP%3E%3CPRE%20class%3D%22lia-code-sample%20language-markup%22%3E%3CCODE%3ESub%20CombineAllInvoices()%0ADim%20xlApp%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20As%20Application%0ADim%20wbMaster%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20As%20Workbook%0ADim%20wbInvoice%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20As%20Workbook%0ADim%20wsMaster%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20As%20Worksheet%0ADim%20wsInvoice%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20As%20Worksheet%0ADim%20strSourceFolderPath%20%20%20%20%20As%20String%0ADim%20strNewFolderPath%20%20%20%20%20%20%20%20As%20String%0ADim%20strNewFileName%20%20%20%20%20%20%20%20%20%20As%20String%0ADim%20strMoveFolderName%20%20%20%20%20%20%20As%20String%0ADim%20fso%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20As%20Object%0ADim%20SourceFolder%20%20%20%20%20%20%20%20%20%20%20%20As%20Object%0ADim%20Invoice%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20As%20Object%0ADim%20rngQty%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20As%20Range%0ADim%20rngTotal%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20As%20Range%0ADim%20lr%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20As%20Long%0ADim%20dlr%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20As%20Long%0ADim%20i%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20As%20Long%0ADim%20Dicsount%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20As%20Double%0A%0AApplication.ScreenUpdating%20%3D%20False%0AApplication.DisplayAlerts%20%3D%20False%0A%0AWith%20Application.FileDialog(msoFileDialogFolderPicker)%0A%20%20%20%20.Title%20%3D%20%22Select%20Invoice%20Folder!%22%0A%20%20%20%20.AllowMultiSelect%20%3D%20False%0A%20%20%20%20If%20.Show%20%26lt%3B%26gt%3B%20-1%20Then%0A%20%20%20%20%20%20%20%20MsgBox%20%22You%20didn't%20select%20any%20Invoice%20Folder.%22%2C%20vbExclamation%0A%20%20%20%20%20%20%20%20Exit%20Sub%0A%20%20%20%20Else%0A%20%20%20%20%20%20%20%20strSourceFolderPath%20%3D%20.SelectedItems(1)%0A%20%20%20%20End%20If%0AEnd%20With%0A%0ASet%20fso%20%3D%20CreateObject(%22Scripting.FileSystemObject%22)%0ASet%20SourceFolder%20%3D%20fso.GetFolder(strSourceFolderPath)%0A%0A'Invoice%20Files%20processed%20by%20the%20code%20will%20be%20transferred%20to%20the%20following%20sub-folder%20in%20the%20chosen%20source%20folder%0AstrMoveFolderName%20%3D%20%22Invoiced%20Moved%22%0AstrMoveFolderName%20%3D%20strMoveFolderName%20%26amp%3B%20%22%20%22%20%26amp%3B%20Format(Now%2C%20%22dd-mmm-yy%20hhmmss%22)%0AstrMoveFolderName%20%3D%20strSourceFolderPath%20%26amp%3B%20%22%5C%22%20%26amp%3B%20strMoveFolderName%0A%0A'Creating%20folder%20to%20move%20already%20processed%20invoice%20files%0Afso.CreateFolder%20(strMoveFolderName)%0A%0AWith%20ThisWorkbook.Worksheets(%22Template%22)%0A%20%20%20%20.Visible%20%3D%20xlSheetVisible%0A%20%20%20%20.Copy%0A%20%20%20%20.Visible%20%3D%20xlSheetVeryHidden%0AEnd%20With%0A%0ASet%20wbMaster%20%3D%20ActiveWorkbook%0ASet%20wsMaster%20%3D%20wbMaster.Worksheets(1)%0AwsMaster.Name%20%3D%20%22All%20Invoices%22%0A%0AOn%20Error%20GoTo%20Skip%0ASet%20xlApp%20%3D%20New%20Application%0A%0AFor%20Each%20Invoice%20In%20SourceFolder.Files%0A%20%20%20%20If%20LCase(fso.GetExtensionName(Invoice))%20%3D%20%22xls%22%20Or%20LCase(fso.GetExtensionName(Invoice))%20%3D%20%22xlsx%22%20Then%0A%20%20%20%20%20%20%20%20If%20Left(Invoice.Name%2C%201)%20%3D%20%22%23%22%20Then%0A%20%20%20%20%20%20%20%20%20%20%20%20Set%20wbInvoice%20%3D%20xlApp.Workbooks.Open(Invoice)%0A%20%20%20%20%20%20%20%20%20%20%20%20Set%20wsInvoice%20%3D%20wbInvoice.Worksheets(%22Invoice%22)%0A%20%20%20%20%20%20%20%20%20%20%20%20%0A%20%20%20%20%20%20%20%20%20%20%20%20Set%20rngQty%20%3D%20wsInvoice.Range(%22D%3AD%22).Find(what%3A%3D%22Qty%22%2C%20lookat%3A%3DxlWhole)%0A%20%20%20%20%20%20%20%20%20%20%20%20%0A%20%20%20%20%20%20%20%20%20%20%20%20If%20Not%20rngQty%20Is%20Nothing%20Then%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20Set%20rngTotal%20%3D%20wsInvoice.Range(%22K%3AK%22).Find(what%3A%3D%22TOTAL*%22%2C%20lookat%3A%3DxlWhole%2C%20MatchCase%3A%3DFalse)%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20lr%20%3D%20rngTotal.Row%20-%205%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20For%20i%20%3D%20rngQty.Row%20%2B%201%20To%20lr%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20If%20wsInvoice.Cells(i%2C%204)%20%26lt%3B%26gt%3B%20%22%22%20And%20wsInvoice.Cells(i%2C%205)%20%26lt%3B%26gt%3B%20%22Discount%22%20Then%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20dlr%20%3D%20wsMaster.Cells.Find(%22*%22%2C%20SearchOrder%3A%3DxlByRows%2C%20SearchDirection%3A%3DxlPrevious).Row%20%2B%201%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20'Invoice%20details%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20wsMaster.Range(%22A%22%20%26amp%3B%20dlr).Value%20%3D%20wsInvoice.Range(%22data5%22).Value%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20wsMaster.Range(%22B%22%20%26amp%3B%20dlr).Value%20%3D%20wsInvoice.Range(%22data6%22).Value%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20wsMaster.Range(%22C%22%20%26amp%3B%20dlr).Value%20%3D%20wsInvoice.Range(%22data7%22).Value%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20wsMaster.Range(%22D%22%20%26amp%3B%20dlr).Value%20%3D%20wsInvoice.Range(%22data8%22).Value%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20wsMaster.Range(%22E%22%20%26amp%3B%20dlr).Value%20%3D%20wsInvoice.Range(%22data9%22).Value%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20wsMaster.Range(%22F%22%20%26amp%3B%20dlr).Value%20%3D%20wsInvoice.Range(%22data10%22).Value%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20wsMaster.Range(%22G%22%20%26amp%3B%20dlr).Value%20%3D%20wsInvoice.Range(%22data1%22).Value%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20wsMaster.Range(%22H%22%20%26amp%3B%20dlr).Value%20%3D%20wsInvoice.Range(%22NO%22).Value%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20wsMaster.Range(%22I%22%20%26amp%3B%20dlr).Value%20%3D%20wsInvoice.Range(%22data2%22).Value%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20'Order%20details%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20wsMaster.Range(%22J%22%20%26amp%3B%20dlr).Value%20%3D%20wsInvoice.Range(%22E%22%20%26amp%3B%20i%20%26amp%3B%20%22%3AJ%22%20%26amp%3B%20i).Value%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20wsMaster.Range(%22K%22%20%26amp%3B%20dlr).Value%20%3D%20wsInvoice.Cells(i%2C%204).Value%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20wsMaster.Range(%22L%22%20%26amp%3B%20dlr).Value%20%3D%20wsInvoice.Cells(i%2C%2011).Value%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20wsMaster.Range(%22M%22%20%26amp%3B%20dlr).Value%20%3D%20wsInvoice.Cells(i%2C%2012).Value%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20End%20If%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20If%20wsInvoice.Cells(i%2C%204)%20%26lt%3B%26gt%3B%20%22%22%20And%20wsInvoice.Cells(i%2C%205)%20%3D%20%22Discount%22%20Then%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20wsMaster.Range(%22N%22%20%26amp%3B%20dlr).Value%20%3D%20wsInvoice.Cells(i%2C%2011).Value%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20wsMaster.Range(%22O%22%20%26amp%3B%20dlr).Value%20%3D%20wsInvoice.Range(%22TOT%22).Value%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20End%20If%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20Next%20i%0A%20%20%20%20%20%20%20%20%20%20%20%20End%20If%0A%20%20%20%20%20%20%20%20%20%20%20%20%0A%20%20%20%20%20%20%20%20%20%20%20%20wbInvoice.Close%20False%0A%20%20%20%20%20%20%20%20%20%20%20%20fso.MoveFile%20Invoice%2C%20strMoveFolderName%20%26amp%3B%20%22%5C%22%20%26amp%3B%20Invoice.Name%0A%20%20%20%20%20%20%20%20End%20If%0A%20%20%20%20End%20If%0ANext%20Invoice%0A%0A'The%20Master%20Invoie%20File%20will%20be%20saved%20in%20this%20folder%0AstrNewFolderPath%20%3D%20strSourceFolderPath%20%26amp%3B%20%22%5C%22%20%26amp%3B%20Format(Now%2C%20%22dd-mmm-yy%20hhmmss%22)%0A%0A'Name%20of%20the%20Master%20File%0AstrNewFileName%20%3D%20%22Master%20Invoice.xlsx%22%0A%0Afso.CreateFolder%20strNewFolderPath%0AWith%20wsMaster.Range(%22A1%22).CurrentRegion%0A%20%20%20%20.Borders.Color%20%3D%20vbBlack%0A%20%20%20%20.Columns.AutoFit%0AEnd%20With%0A%0AwbMaster.SaveAs%20strNewFolderPath%20%26amp%3B%20%22%5C%22%20%26amp%3B%20strNewFileName%2C%2051%0AwbMaster.Close%20True%0AMsgBox%20%22Master%20File%20has%20been%20saved%20successfully...%22%20%26amp%3B%20vbNewLine%20%26amp%3B%20vbNewLine%20%26amp%3B%20_%0A%20%20%20%20%20%20%20%20strNewFolderPath%20%26amp%3B%20%22%5C%22%20%26amp%3B%20strNewFileName%2C%20vbInformation%0A%20%20%20%20%20%20%20%20%0ASkip%3A%0AxlApp.Quit%0ASet%20xlApp%20%3D%20Nothing%0AApplication.DisplayAlerts%20%3D%20True%0AApplication.ScreenUpdating%20%3D%20True%0AEnd%20Sub%3C%2FCODE%3E%3C%2FPRE%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-822099%22%20slang%3D%22en-US%22%3ERe%3A%20Put%20multiple%20fields%20from%20various%20excel%20invoices%20into%201%20spreadsheet%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-822099%22%20slang%3D%22en-US%22%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F394231%22%20target%3D%22_blank%22%3E%40Subodh_Tiwari_sktneer%3C%2FA%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EThis%20works%20perfectly!%20Thank%20you%20so%20much.%3C%2FP%3E%3CP%3EI'm%20still%20going%20over%20all%20the%20code%20to%20learn%20what%20it%20does%20but%20I%20have%20been%20able%20to%20adapt%20parts%20of%20it%20further%20for%20what%20I%20need%20done.%20The%20different%20%22If%20Then%20statements%22%20are%20making%20me%20think%20and%20in%20what%20order%20I%20need%20to%20add%20some%20extra%20things%2C%20but%20so%20far%20so%20good!%20I%20just%20need%20to%20familiarize%20myself%20with%20it%20more.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EThank%20you%20again%20for%20your%20help!%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-822129%22%20slang%3D%22en-US%22%3ERe%3A%20Put%20multiple%20fields%20from%20various%20excel%20invoices%20into%201%20spreadsheet%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-822129%22%20slang%3D%22en-US%22%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F397625%22%20target%3D%22_blank%22%3E%40RogPos%3C%2FA%3E%26nbsp%3B%20If%20all%20invoice%20files%20are%20structured%20identically%2C%20you%20can%20also%20collect%20all%20the%20data%20with%20Power%20Query%20without%20writing%20a%20single%20line%20of%20VBA.%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-822180%22%20slang%3D%22en-US%22%3ERe%3A%20Put%20multiple%20fields%20from%20various%20excel%20invoices%20into%201%20spreadsheet%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-822180%22%20slang%3D%22en-US%22%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F7724%22%20target%3D%22_blank%22%3E%40Ingeborg%20Hawighorst%3C%2FA%3E%26nbsp%3B%3C%2FP%3E%3CP%3EI%20actually%20wanted%20to%20use%20Power%20Query%20originally%20and%20tried%20to%20figure%20it%20out%2C%20but%20I%20didn't%20understand%20how%20to%20get%20it%20to%20put%20the%20data%20into%20the%20fields%20I%20wanted.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EThis%20was%20as%20far%20as%20I%20could%20figure%20out%20(see%20attached).%20It%20correctly%20opened%20up%20my%20sample%20files%20but%20put%20the%20info%20all%20over%20the%20place%2C%20and%20I%20don't%20know%20how%20to%20correctly%20order%20it%20into%20how%20I%20wanted%20it%20in%20my%20above%20post's%20example.%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-822354%22%20slang%3D%22en-US%22%3ERe%3A%20Put%20multiple%20fields%20from%20various%20excel%20invoices%20into%201%20spreadsheet%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-822354%22%20slang%3D%22en-US%22%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F397625%22%20target%3D%22_blank%22%3E%40RogPos%3C%2FA%3E%26nbsp%3B%3C%2FP%3E%3CP%3EYou're%20welcome!%20Glad%20it%20worked%20as%20desired.%3C%2FP%3E%3CP%3EThanks%20for%20the%20feedback!%3C%2FP%3E%3C%2FLINGO-BODY%3E
RogPos
Occasional Contributor

I use Excel (Office 365) to create invoices, and I wanted to see if it's possible to take all invoice files I have and create 1 spreadsheet that has everything listed. Basically I want to consolidate all my customers into 1 list. I believe all my customer data is consistently in the same Column/Row per each invoice, although the Items/Description lines change.

 

See attached photos below for my invoice example, and the end result I would like to achieve.

 

ExampleInvoice.jpgEndResult_example.jpg

 

9 Replies

@RogPos 

That's doable with VBA provided you give us more details about the layout of the Invoice Sheet. Why not upload a sample invoice sheet with some dummy data in it with the same layout?

@Subodh_Tiwari_sktneer 

 

I attached 4 sample invoices that represent my usual invoice layouts.

I tried using Power Query, but I'm not familiar with how to use it properly and the results were listed all over the place, so VBA sounds promising.

 

Thank you!

@RogPos 

 

You uploaded invoices without any dummy data, never mind.

Where exactly you will enter the Invoice#?

Is it possible for you to upload one invoice with some dummy data only in the fields which are to be fetched into Master Invoice File?

Btw I saw that you have created the Named Ranges on invoice sheet, that's a good idea but at the same time names of the named ranges are not meaningful. You could name them like _Invoice, _CompanyName, _Address etc.

 

Few queries...

 

1) When a Master Invoice Workbook is created with details of all the invoices, how would you like to name it? Will it be a new Master Invoice with a datetime stamp in the file name each time you run the code.

 

2) If the above assumption is not correct, would you always like to have one Master Invoice File and  delete any existing data in previously Existing Master Invoice file and then append data from all the invoices? Or once you run the code, all the invoices which are processed by the code should be moved to another sub-folder (say Consolidated Invoices in the same directory) so that you don't duplicate the data in the Master Invoice File while running the code next time?

 

3) I assume that all the invoices are saved in the same folder. Can I also assume that names of all the invoice files start with a # sign i.e. #1000_CompanyA-Project1.xls etc.? I am asking this as code needs way to differentiate between an Invoice file and other files if files other than invoice files are also saved in the same folder.

 

4) Will all the invoice files always have the .xls file extension?

 

5) Is it okay if the code opens a Folder Picker Dialog Window for you to choose the source folder where all the invoice files are saved? Or it is always a fixed folder? If yes, what's the full path of the source folder?

 

@Subodh_Tiwari_sktneer 

  1. You uploaded invoices without any dummy data, never mind.

    All the invoices I uploaded should have dummy data in the "Invoice" worksheet. I just randomly entered values that match how my layout is. Unless I don't understand what you mean by dummy data?
  2. Where exactly you will enter the Invoice#?

    I enter it directly in the field next to "Invoice No." I believe the field is named NO.
  3. Is it possible for you to upload one invoice with some dummy data only in the fields which are to be fetched into Master Invoice File?

    At bare minimum it would just be the "Customer" info: Name, Address, City, State, Zip, Phone, and the Invoice Number. (I'm not sure if it's possible to put in the Qty, Description, Unit Price since the locations vary with each invoice and they are multiple lines. It would be nice, but looks too complicated.) I'm only using information from the "Invoice" worksheet, not the "customize" one. For example:
    NameAddressCityStateZipPhoneInvoice No
    Company AAddress ACity AState AZip APhone A1000
    Company BAddress BCity BState BZip BPhone B1001
  4. Btw I saw that you have created the Named Ranges on invoice sheet, that's a good idea but at the same time names of the named ranges are not meaningful. You could name them like _Invoice, _CompanyName, _Address etc.

    I actually didn't create the template/worksheets, someone else did a long time ago. But I agree with you, the naming isn't good.

1) When a Master Invoice Workbook is created with details of all the invoices, how would you like to name it? Will it be a new Master Invoice with a datetime stamp in the file name each time you run the code.

Named after the folder that the invoices are in + datetime stamp I was thinking.

 

2) If the above assumption is not correct, would you always like to have one Master Invoice File and  delete any existing data in previously Existing Master Invoice file and then append data from all the invoices? Or once you run the code, all the invoices which are processed by the code should be moved to another sub-folder (say Consolidated Invoices in the same directory) so that you don't duplicate the data in the Master Invoice File while running the code next time?

 

I like the idea of moving to a sub-folder so I don't have duplicate data, but I don't know if that will be good in practice, unless it's easy for me to disable those lines of code if needed? But just saving everything with the folder name + datetime stamp is fine.

 

3) I assume that all the invoices are saved in the same folder. Can I also assume that names of all the invoice files start with a # sign i.e. #1000_CompanyA-Project1.xls etc.? I am asking this as code needs way to differentiate between an Invoice file and other files if files other than invoice files are also saved in the same folder.

 

They are all in the same main folder(s) with some having subfolders.

They all start that same way: # followed by invoice number and underscore.

 

4) Will all the invoice files always have the .xls file extension?

 

xls or xlsx

 

5) Is it okay if the code opens a Folder Picker Dialog Window for you to choose the source folder where all the invoice files are saved? Or it is always a fixed folder? If yes, what's the full path of the source folder?

 

Folder Picker Dialog Window is fine since I have different folders I need to run it in.

 

 

Solution

@RogPos 

 

Please find the attached with a code called "CombineAllInvoices" on m_CombineAllInvoices Module.

The file has a hidden sheet called Template in it with the headers only.

You will also find a button called "Combine All Invoices" on Main Sheet and you may click this button to run the code.

 

Here is the code....

Sub CombineAllInvoices()
Dim xlApp                   As Application
Dim wbMaster                As Workbook
Dim wbInvoice               As Workbook
Dim wsMaster                As Worksheet
Dim wsInvoice               As Worksheet
Dim strSourceFolderPath     As String
Dim strNewFolderPath        As String
Dim strNewFileName          As String
Dim strMoveFolderName       As String
Dim fso                     As Object
Dim SourceFolder            As Object
Dim Invoice                 As Object
Dim rngQty                  As Range
Dim rngTotal                As Range
Dim lr                      As Long
Dim dlr                     As Long
Dim i                       As Long
Dim Dicsount                As Double

Application.ScreenUpdating = False
Application.DisplayAlerts = False

With Application.FileDialog(msoFileDialogFolderPicker)
    .Title = "Select Invoice Folder!"
    .AllowMultiSelect = False
    If .Show <> -1 Then
        MsgBox "You didn't select any Invoice Folder.", vbExclamation
        Exit Sub
    Else
        strSourceFolderPath = .SelectedItems(1)
    End If
End With

Set fso = CreateObject("Scripting.FileSystemObject")
Set SourceFolder = fso.GetFolder(strSourceFolderPath)

'Invoice Files processed by the code will be transferred to the following sub-folder in the chosen source folder
strMoveFolderName = "Invoiced Moved"
strMoveFolderName = strMoveFolderName & " " & Format(Now, "dd-mmm-yy hhmmss")
strMoveFolderName = strSourceFolderPath & "\" & strMoveFolderName

'Creating folder to move already processed invoice files
fso.CreateFolder (strMoveFolderName)

With ThisWorkbook.Worksheets("Template")
    .Visible = xlSheetVisible
    .Copy
    .Visible = xlSheetVeryHidden
End With

Set wbMaster = ActiveWorkbook
Set wsMaster = wbMaster.Worksheets(1)
wsMaster.Name = "All Invoices"

On Error GoTo Skip
Set xlApp = New Application

For Each Invoice In SourceFolder.Files
    If LCase(fso.GetExtensionName(Invoice)) = "xls" Or LCase(fso.GetExtensionName(Invoice)) = "xlsx" Then
        If Left(Invoice.Name, 1) = "#" Then
            Set wbInvoice = xlApp.Workbooks.Open(Invoice)
            Set wsInvoice = wbInvoice.Worksheets("Invoice")
            
            Set rngQty = wsInvoice.Range("D:D").Find(what:="Qty", lookat:=xlWhole)
            
            If Not rngQty Is Nothing Then
                Set rngTotal = wsInvoice.Range("K:K").Find(what:="TOTAL*", lookat:=xlWhole, MatchCase:=False)
                lr = rngTotal.Row - 5
                For i = rngQty.Row + 1 To lr
                    If wsInvoice.Cells(i, 4) <> "" And wsInvoice.Cells(i, 5) <> "Discount" Then
                        dlr = wsMaster.Cells.Find("*", SearchOrder:=xlByRows, SearchDirection:=xlPrevious).Row + 1
                        
                        'Invoice details
                        wsMaster.Range("A" & dlr).Value = wsInvoice.Range("data5").Value
                        wsMaster.Range("B" & dlr).Value = wsInvoice.Range("data6").Value
                        wsMaster.Range("C" & dlr).Value = wsInvoice.Range("data7").Value
                        wsMaster.Range("D" & dlr).Value = wsInvoice.Range("data8").Value
                        wsMaster.Range("E" & dlr).Value = wsInvoice.Range("data9").Value
                        wsMaster.Range("F" & dlr).Value = wsInvoice.Range("data10").Value
                        wsMaster.Range("G" & dlr).Value = wsInvoice.Range("data1").Value
                        wsMaster.Range("H" & dlr).Value = wsInvoice.Range("NO").Value
                        wsMaster.Range("I" & dlr).Value = wsInvoice.Range("data2").Value
                        
                        'Order details
                        wsMaster.Range("J" & dlr).Value = wsInvoice.Range("E" & i & ":J" & i).Value
                        wsMaster.Range("K" & dlr).Value = wsInvoice.Cells(i, 4).Value
                        wsMaster.Range("L" & dlr).Value = wsInvoice.Cells(i, 11).Value
                        wsMaster.Range("M" & dlr).Value = wsInvoice.Cells(i, 12).Value
                    End If
                    
                    If wsInvoice.Cells(i, 4) <> "" And wsInvoice.Cells(i, 5) = "Discount" Then
                        wsMaster.Range("N" & dlr).Value = wsInvoice.Cells(i, 11).Value
                        wsMaster.Range("O" & dlr).Value = wsInvoice.Range("TOT").Value
                    End If
                Next i
            End If
            
            wbInvoice.Close False
            fso.MoveFile Invoice, strMoveFolderName & "\" & Invoice.Name
        End If
    End If
Next Invoice

'The Master Invoie File will be saved in this folder
strNewFolderPath = strSourceFolderPath & "\" & Format(Now, "dd-mmm-yy hhmmss")

'Name of the Master File
strNewFileName = "Master Invoice.xlsx"

fso.CreateFolder strNewFolderPath
With wsMaster.Range("A1").CurrentRegion
    .Borders.Color = vbBlack
    .Columns.AutoFit
End With

wbMaster.SaveAs strNewFolderPath & "\" & strNewFileName, 51
wbMaster.Close True
MsgBox "Master File has been saved successfully..." & vbNewLine & vbNewLine & _
        strNewFolderPath & "\" & strNewFileName, vbInformation
        
Skip:
xlApp.Quit
Set xlApp = Nothing
Application.DisplayAlerts = True
Application.ScreenUpdating = True
End Sub

 

 

@Subodh_Tiwari_sktneer 

 

This works perfectly! Thank you so much.

I'm still going over all the code to learn what it does but I have been able to adapt parts of it further for what I need done. The different "If Then statements" are making me think and in what order I need to add some extra things, but so far so good! I just need to familiarize myself with it more.

 

Thank you again for your help!

 

@RogPos  If all invoice files are structured identically, you can also collect all the data with Power Query without writing a single line of VBA.

@Ingeborg Hawighorst 

I actually wanted to use Power Query originally and tried to figure it out, but I didn't understand how to get it to put the data into the fields I wanted.

 

This was as far as I could figure out (see attached). It correctly opened up my sample files but put the info all over the place, and I don't know how to correctly order it into how I wanted it in my above post's example.

@RogPos 

You're welcome! Glad it worked as desired.

Thanks for the feedback!

Related Conversations