Forum

Copying from one wo...
 
Notifications
Clear all

Copying from one workbook to another when condition is met

6 Posts
2 Users
0 Reactions
79 Views
(@gumsaiga)
Posts: 8
Active Member
Topic starter
 

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:UsersEric LauDesktopCCIPurchase Order by Vendor REportsPurchase Order Details by Vendor (" & yy & "-" & mm & "-" & dd & ")"

Workbooks.Open Filename:="C:UsersEric LauDesktopCCIPurchase Order by Vendor REportsPurchase 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!

 
Posted : 12/11/2019 11:09 am
(@catalinb)
Posts: 1937
Member Admin
 

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?

 
Posted : 14/11/2019 12:39 am
(@gumsaiga)
Posts: 8
Active Member
Topic starter
 

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

 
Posted : 15/11/2019 11:24 am
(@catalinb)
Posts: 1937
Member Admin
 

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.

 
Posted : 15/11/2019 12:19 pm
(@gumsaiga)
Posts: 8
Active Member
Topic starter
 

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.

 
Posted : 17/11/2019 4:08 pm
(@catalinb)
Posts: 1937
Member Admin
 

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

 
Posted : 17/11/2019 11:50 pm
Share: