Forum

Conditionally Copy ...
 
Notifications
Clear all

Conditionally Copy and paste between csv file & xls

8 Posts
3 Users
0 Reactions
118 Views
(@leonardo1234)
Posts: 26
Eminent Member
Topic starter
 

Hello Everyone, I am looking for a macro plz see the details below

Condition 1) Only If column K of sample1.xls is greater than Column D of sample1.xls & Column H of sample1.xls is Greater than column K of sample1.xls then Match Column B of sample1.xls with column B of sample2.csv & if it is there then do nothing & if it is not present then paste the column B data of sample1.xls to column B of sample2.csv

Condition 2) Only If column K of sample1.xls is lower than Column D of sample1.xls & Column H of sample1.xls is lower than column K of sample1.xls then Match Column B of sample1.xls with column B of sample2.csv & if it is there then do nothing & if it is not present then paste the column B data of sample1.xls to column B of sample2.csv

Plz Note
All files are located in a different path (So in the macro the path will be hardcoded, Assume any path & I will edit the path manually by myself)
Sheet name can be anything
Macro will be putted in a vba.xlsm

Plz see the file that I have attached below

 
Posted : 07/06/2020 9:40 am
(@purfleet)
Posts: 412
Reputable Member
 

Hi Sholtan

This is quite simular the last few questions you have posted in the forum - have you tried to create it yourself?

While the actual process of opening files etc are straight forward the comparisons you want to make are quite complex.

You seem happy enough to edit code, so i assume you are willing to learn to code your own stuff and once you start you wont want to stop.

As a pointer, i would open the xls file and then import the csv into the same workbook, you can then use standard formulas to do the comparisons you want to and then save the output as a new workbook. All a macro is doing is automating the manual steps - you just need to work through each issue as they happen.

To open a workbook

Sub OpenWb()

Workbooks.Open ("C:MOTHsample1.xls")

End Sub

To open the csv and copy to sample1.xls (made a bit more complicated by the .xls to start with rather than a .xlsx)

Sub Opencsvandcopy()

Workbooks.Open ("C:MOTHsample2.csv")
Worksheets("sample2").Range("a1:k5").Copy

Workbooks("sample1.xls").Sheets.Add.Name = "sample2"

Workbooks("sample1.xls").Worksheets("sample2").Range("a1").PasteSpecial xlPasteAll

End Sub

I hope this helps

Purfleet

 
Posted : 07/06/2020 5:34 pm
Philip Treacy
(@philipt)
Posts: 1629
Member Admin
 

yes, these qs seem like homework ....

 
Posted : 07/06/2020 6:57 pm
(@leonardo1234)
Posts: 26
Eminent Member
Topic starter
 

This is not possible, that this question is homework

whenever i ask question, u say this seems like homework

I face issues in making the macro,in which csv files are present, so that's y i always ask the question related to csv files

Purfleet Sir i am unable to make the macro for this 

So plz have a relook & provide me the completed code

 
Posted : 08/06/2020 1:29 am
(@purfleet)
Posts: 412
Reputable Member
 

Hi Sholtan

I am happy to help but my time is limited, i have started you off with the automated import into Excel. Can you figure out the logic to do what you want (even if it was with formulas)?

Then post it back on here and i might be able to automate.

As i said before, it is simular to the last question you asked, so maybe there are lessons to be lernt from that thread?

Purfleet

 
Posted : 09/06/2020 4:17 am
(@leonardo1234)
Posts: 26
Eminent Member
Topic starter
 

Either of these 2 conditions are to result in macro will copy value in column I of sample1.xls to field 2(column B) of Sample2.csv on a new line:
Condition 1) Only If column K of sample1.xls is greater than Column D of sample1.xls & Column H of sample1.xls is Greater than column K of sample1.xls then Match Column I of sample1.xls with second field values (column B) of sample2.csv & if it is there then do nothing & if it is not present then paste the column I data of sample1.xls to append second field values (column B) of sample2.csv

Condition 2) Only If column K of sample1.xls is lower than Column D of sample1.xls & Column H of sample1.xls is lower than column K of sample1.xls then Match Column I of sample1.xls with second field values (column B) of sample2.csv & if it is there then do nothing & if it is not present then paste the column I data of sample1.xls to append second field values (column B) of sample2.csv

 
Posted : 09/06/2020 5:03 am
(@leonardo1234)
Posts: 26
Eminent Member
Topic starter
 

Problem Solved

 
Posted : 10/06/2020 12:31 pm
Philip Treacy
(@philipt)
Posts: 1629
Member Admin
 

Hi Sholtan,

Please post the solution so that others may learn.

regards

Phil

 
Posted : 10/06/2020 8:19 pm
Share: