Results 1 to 10 of 49

Thread: Copy and Paste based on comparisons/Match and calculations of cells in two workbooks

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #11
    Senior Member
    Join Date
    Jul 2019
    Posts
    382
    Rep Power
    0
    Sir there is one more issue in the code so plz have a look
    i am attaching the file and the code


    Code:
    Option Explicit
    ' file name is sample1.xlsx
    ' compare column O is greater or column P is greater
    ' if column O is greater then calculate the 0.50% of column O and after getting the 0.50% of column O multiply the same with column L and paste the result in column Y
    ' if column P is greater then calculate the 0.50% of column P and after getting the 0.50% of column P multiply the same with column L and paste the result in column Y
    ' save the changes and close the file
    '
    Sub Vixer2() ' http://www.excelfox.com/forum/showth...ultiply-by-vba
    '1a) Workbook and worksheets info
    Dim Wb1 As Workbook: Set Wb1 = Workbooks.Open("C:\Users\WolfieeeStyle\Desktop\ap.xls") ' Set using workbooks collection object of open files
    Dim Ws1 As Worksheet: Set Ws1 = Wb1.Worksheets.Item(1) ' First worksheet, (as worksheet object) in open file "sample1.xlsx"
    Dim Lr1 As Long, Lr2 As Long
     Let Lr1 = 4: Lr2 = 4 ' For this example I am using just three rows of data, and a header
    Rem 3
    Dim Cnt As Long ' Main Loop for all data rows ================================================
        ' 3a) ' compare column O is greater or column P is greater
        For Cnt = 2 To Lr1
        Dim Bigger As Double
            If Ws1.Range("O" & Cnt & "").Value > Ws1.Range("P" & Cnt & "").Value Then ' if column O is greater
             Let Bigger = Ws1.Range("O" & Cnt & "").Value
            Else
             Let Bigger = Ws1.Range("P" & Cnt & "").Value ' if column P is greater
            End If
        Dim Rslt As Double '
         Let Rslt = Bigger * (0.5 / 100) * Ws1.Range("L" & Cnt & "").Value ' calculate the 0.50% of that and multiply the same with column L
        '3b) paste the result to sample1.xlsx column Y
         Let Ws1.Range("Y" & Cnt & "").Value = Rslt
        Next Cnt '     Main Loop for all rows =====================================================
    ' save the changes and close the file
     Wb1.Close savechanges:=True
    End Sub
    Attached Files Attached Files
    Last edited by DocAElstein; 08-11-2019 at 12:04 PM. Reason: Code tags added

Similar Threads

  1. Replies: 85
    Last Post: 06-09-2020, 05:58 PM
  2. Copy paste data based on criteria
    By analyst in forum Excel Help
    Replies: 7
    Last Post: 01-13-2014, 12:46 PM
  3. Replies: 4
    Last Post: 12-12-2013, 06:16 PM
  4. Replies: 8
    Last Post: 10-31-2013, 12:38 AM
  5. Replies: 2
    Last Post: 02-11-2013, 08:13 PM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •