Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

copy paste conditionally

Status
Not open for further replies.

rider1234

Programmer
Jun 21, 2019
51
0
0
IN
If column E of sample1.xls matches with column A of sample2.xlsx then look column O of sample1.xls and column P of sample1.xls & if column O of sample1.xls is higher then calculate the 0.50% of column O of sample1.xls or if column P of sample1.xls is higher then calculate the 0.50% of that and multiply the same with column L of sample1.xls(column L can contain - minus sign so ignore that or it will not contain any sign with numbers so we have to look only the numbers) and add that data to Column R of sample1.xls and paste the result to sample2.xlsx from column C(if column C has data then paste to column D and if Column D has then column E and so on)
Vba is placed in a different file
all files are located in same path

sample1.xls and sample2.xlsx has headers so ignore the first row
 
Hi,

Please post your code and explain where it is you are experiencing difficulty.

You have already been given complete procedures that perform much of what you describe. You must attempt to adapt that code to this task as best you can.

This is Tek TIPS, not Tek CODING.

Skip,
[sub]
[glasses]Just traded in my OLD subtlety...
for a NUance![tongue][/sub]
"The most incomprehensible thing about the universe is that it is comprehensible" A. Einstein
AD1D550E-FCB5-4AB6-A3C8-1F86CACE2554_ne1bcz.jpg
 
Code:
Sub Code()
    Dim wbk1 As Workbook
    Dim wsh1 As Worksheet
    Dim wbk2 As Workbook
    Dim wsh2 As Worksheet
    Dim r1 As Range, vRow2 As Variant, sLookup As String
    
    Application.ScreenUpdating = False
    
    Set wbk1 = Workbooks.Open(ThisWorkbook.Path & "\sample1.xls")
    Set wsh1 = wbk1.Worksheets(1)
    
    Set wbk2 = Workbooks.Open(ThisWorkbook.Path & "\sample2.xlsx")
    Set wsh2 = wbk2.Worksheets(1)
    
    With wsh1
        For Each r1 In .Range(.Cells(2, "E"), .Cells(2, "E").End(xlDown))
            sLookup = .Cells(r1.Row, "E").Value
            vRow2 = Application.Match(sLookup, wsh2.Range("A:A"), 0)
                
     
    End With
    
    Application.DisplayAlerts = False
    wbk1.Close SaveChanges:=True
    wbk2.Close SaveChanges:=True
    Application.DisplayAlerts = True
    
    Application.ScreenUpdating = True
End Sub


i am unable to do the next step plz have a look in it Sir
 
This is you original post:

Code:
If column E of sample1.xls matches with column A of sample2.xlsx then 
    look column O of sample1.xls and column P of sample1.xls

    if column O of sample1.xls is higher then 
        calculate the 0.50% of column O of sample1.xls or 
    if column P of sample1.xls is higher then 
        calculate the 0.50% of that 

    and multiply the same with column L of sample1.xls

    (column L can contain - minus sign so ignore that or 
    it will not contain any sign with numbers 
    so we have to look only the numbers) 

    and add that data to Column R of sample1.xls and 

    paste the result to sample2.xlsx from column C

    (if column C has data then 
        paste to column D and 
     if Column D has then 
        column E and so on)

I would first work on this 'pseudo-code' to establish your logic.
For example, first line:[tt]
If column E of sample1.xls matches with column A of sample2.xlsx then [/tt]
What do you mean by "[tt]matches[/tt]" ?
Do you mean all values in column E have to match all values in column A? I.e. E2 = A2, E3 = A3, E4 = A4, and so on...?

And go on down your logic and write it in simple English.
Then you can convert it - line by line - into VBA code.


---- Andy

There is a great need for a sarcasm font.
 
You did not try hard enough.

Think about it and go on to column O.

Skip,
[sub]
[glasses]Just traded in my OLD subtlety...
for a NUance![tongue][/sub]
"The most incomprehensible thing about the universe is that it is comprehensible" A. Einstein
AD1D550E-FCB5-4AB6-A3C8-1F86CACE2554_ne1bcz.jpg
 
Sir i tried in many ways after that i have posted the same i googled and i saw examples like this problem but i was unsuccessful to resolve the same
 
If you cannot or will not make this fairly simple association from one example to your task and at least demonstrate that attempt, then you must be in way over your head.

Therefore, you ought to locate a competent VBA coder in your area and hire such an individual to perform this coding and what you will need in the future.

Skip,
[sub]
[glasses]Just traded in my OLD subtlety...
for a NUance![tongue][/sub]
"The most incomprehensible thing about the universe is that it is comprehensible" A. Einstein
AD1D550E-FCB5-4AB6-A3C8-1F86CACE2554_ne1bcz.jpg
 
Sir it will take some time to understand sir i have tried but i am blank about this problem
so plz help i will learn something new about vba from this problem sir so plz help
 
The ball is in your court.

Skip,
[sub]
[glasses]Just traded in my OLD subtlety...
for a NUance![tongue][/sub]
"The most incomprehensible thing about the universe is that it is comprehensible" A. Einstein
AD1D550E-FCB5-4AB6-A3C8-1F86CACE2554_ne1bcz.jpg
 
the ball is in your court means
Sir u know from the starting that this problem is not like a nornal question thats y i started the post otherwise i am solving the smaller vba problems
 
You have a tip, a very big tip in the solutions already provided.

Now it is up to you to TRY. Just try to do the next requirement and post it in your code.

When you look at the given solutions, notice that each If has an End If, each For has a Next, each With has an End With.

Skip,
[sub]
[glasses]Just traded in my OLD subtlety...
for a NUance![tongue][/sub]
"The most incomprehensible thing about the universe is that it is comprehensible" A. Einstein
AD1D550E-FCB5-4AB6-A3C8-1F86CACE2554_ne1bcz.jpg
 
Sir we have already use the application.matchlookup of column E and Column A perfectly
i am unable to do from that part
 
Then you need to hire a coding expert. It will never end.

Skip,
[sub]
[glasses]Just traded in my OLD subtlety...
for a NUance![tongue][/sub]
"The most incomprehensible thing about the universe is that it is comprehensible" A. Einstein
AD1D550E-FCB5-4AB6-A3C8-1F86CACE2554_ne1bcz.jpg
 
Sir i am not a professional guy like u
what i know and what i understand i told u
if i am not understanding what u mean to say then plz provide me the code so that i can learn from the same and from my mistakes
 
If c.Offset(, 15) > c.Offset(, 16) Then
like this will be the next step
 
Where is c in your code? There is no relationship!

Skip,
[sub]
[glasses]Just traded in my OLD subtlety...
for a NUance![tongue][/sub]
"The most incomprehensible thing about the universe is that it is comprehensible" A. Einstein
AD1D550E-FCB5-4AB6-A3C8-1F86CACE2554_ne1bcz.jpg
 
Sir plz have a look i am blank about this problem
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top