• 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

Copying from one workbook to another when condition is met|VBA & Macros|Excel Forum|My Online Training Hub

You are here: Home / Copying from one workbook to another when condition is met|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 & MacrosCopying from one workbook to anothe…
sp_PrintTopic sp_TopicIcon
Copying from one workbook to another when condition is met
Avatar
eric lau
Member
Members
Level 0
Forum Posts: 8
Member Since:
May 8, 2019
sp_UserOfflineSmall Offline
1
November 12, 2019 - 1:09 am
sp_Permalink sp_Print

Hello,

 

I have cut a small section of a report that i want to create a code for. The idea is to cut the notes on column P from yesterday to today's report so i don't have to manually cut and paste them.

Goal: If PO number from column B(Purchase Order Details by Vendor (2019-11-01)) is equal to PO number from previous day(Purchase Order Details by Vendor (2019-10-31)) then copy the notes to column P for today's workbook. 

Challenges: the PO# will be on a different row day by day as Purchase orders close or open.. so for example PO 009313 might not be on row 26 on Nov 2nd's report.

I only got the code to open the workbooks on my desktop and i am still researching on how to do the rest. 

What i got so far:

Option Explicit

Sub Open_workbook_Basic()

Dim dd As Integer

Dim mm As Integer

Dim yy As Integer

dd = Day(Date)

mm = Month(Date)

yy = Year(Date)

Workbooks.Open Filename:="C:\Users\Eric Lau\Desktop\CCI\Purchase Order by Vendor REports\Purchase Order Details by Vendor (" & yy & "-" & mm & "-" & dd & ")"

Workbooks.Open Filename:="C:\Users\Eric Lau\Desktop\CCI\Purchase Order by Vendor REports\Purchase Order Details by Vendor (" & yy & "-" & mm & "-" & dd-1 & ")"

End Sub

I would appreciate it if anyone can help with creating the code or linking resources or older posts that have requested the same thing. 

 

Thank you for your help!

Avatar
Catalin Bombea
Iasi, Romania
Admin
Level 10
Forum Posts: 1807
Member Since:
November 8, 2013
sp_UserOfflineSmall Offline
2
November 13, 2019 - 2:39 pm
sp_Permalink sp_Print

Hi Eric,

The easiest way is to use Power Query to take the data from those 2 files and combine the information, a visual basic solution is much more difficult to implement, to cover all scenarios (including error checks, in case the file you refer does not exist in folder).

There is no unique match though, an order may be found in more than one row. This means that there may be multiple comments for the same order, not just one, what do you want to do in these cases?

Avatar
eric lau
Member
Members
Level 0
Forum Posts: 8
Member Since:
May 8, 2019
sp_UserOfflineSmall Offline
3
November 15, 2019 - 1:24 am
sp_Permalink sp_Print

Hi Catalin,

 

I am intrigued by the use of Power Query to accomplish this. How will you go about accomplishing this? 

 

As for the comments, if the same PO number exist for line 10 & 11 per se, i would want the comment pasted on line 10 for line 10 and line 11 for 11.

 

Thank you for your advice and help in advance.  

 

-Eric Lau

Avatar
Catalin Bombea
Iasi, Romania
Admin
Level 10
Forum Posts: 1807
Member Since:
November 8, 2013
sp_UserOfflineSmall Offline
4
November 15, 2019 - 2:19 am
sp_Permalink sp_Print

That will not work, as you clearly mentioned that the PO might be on a different row in the second file, a UNIQUE identifier is required. I tried to use a second column (warehouse id) as a second key to create a unique identifier, but there are still duplicates.

See the file attached for an example. Change the path to the files in settings, then press refresh All in Data tab. I used for testing the file provided and a copy of the same file, might need adjustments if your real files don't have the same structure.

Avatar
eric lau
Member
Members
Level 0
Forum Posts: 8
Member Since:
May 8, 2019
sp_UserOfflineSmall Offline
5
November 17, 2019 - 6:08 am
sp_Permalink sp_Print

Hello,

Sorry for the late response. I am doing some research on this tool as well but I replaced the link with the desktop link and refreshed. It gave me an error saying : [Expression.Error] The column 'Austin Foams Plastics' of the table wasn't found. 

What is wrong with the tables? Thanks in advance.

Avatar
Catalin Bombea
Iasi, Romania
Admin
Level 10
Forum Posts: 1807
Member Since:
November 8, 2013
sp_UserOfflineSmall Offline
6
November 17, 2019 - 1:50 pm
sp_Permalink sp_Print

I removed the step #"Changed Type" from both queries, that step usually has hard typed column names in it.

sp_Feed
Go to top
Forum Timezone: Australia/Brisbane
Most Users Ever Online: 245
Currently Online: Ruth Savage, Andy Kirby, Roy Lutke, Jeff Krueger
Guest(s) 9
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:
John Chisholm
vexokeb sdfg
John Jack
Malcolm Toy
Ray-Yu Yang
George Shihadeh
Naomi Rumble
Uwe von Gostomski
Jonathan Jones
drsven
Forum Stats:
Groups: 3
Forums: 24
Topics: 6212
Posts: 27236

 

Member Stats:
Guest Posters: 49
Members: 31889
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.