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. #36
    Senior Member
    Join Date
    Jul 2019
    Posts
    382
    Rep Power
    0

    Macro Correction(iF Condition match then replace the data)

    Hi Experts,

    I am looking for a macro that will do the below things
    Plz see the sample file
    there are 3 files ap.xls & BasketOrder.xlsx & macro.xlsm (macro will be placed in macro.xlsm),both files are located in different places so the path will be hardcoded in the macro so that i can change it as per my needs
    sheet name can be anything


    If column J is BUY of BasketOrder.xlsx then add 1% of column O of ap.xls to column O of ap.xls and compare column O of ap.xls with column L of BasketOrder.xlsx and if column O of ap.xls is smaller than column L of BasketOrder then replace column L of BasketOrder data with column O of ap.xls data(with that added 1% of column O of ap.xls) else do nothing

    Or

    If column J is SELL of BasketOrder.xlsx then subtract 1% of column P of ap.xls to column P of ap.xls and compare column P of ap.xls with column L of BasketOrder.xlsx and if column P of ap.xls is Greater than column L of BasketOrder then replace column L of BasketOrder data with column P data of ap.xls (with that subtract 1% of column P of ap.xls) else do nothing



    Thnx for the Help

    macro will be placed in a seperate file




    This macro i have for this problem but some issue is there
    Code:
    Sub STEP8()
        Application.ScreenUpdating = False
        Dim wb1 As Workbook
        Dim wb2 As Workbook
        Dim ws1 As Worksheet
        Dim ws2 As Worksheet
        Dim TempValue As Double
        
        Dim RowCount1 As Integer
        Dim ColumnCount1 As Integer
        Dim RowCount2 As Integer
        Dim ColumnCount2 As Integer
        Dim BOmyArray() As Variant
        Dim APmyArray() As Variant
        
        BOExcellFilePath = "C:\Users\WolfieeeStyle\Desktop\WolfieeeStyle\9.15\Files\BasketOrder.xlsx"
        APExcellFilePath = "C:\Users\WolfieeeStyle\Desktop\ap.xls"
        
        Set wb1 = Workbooks.Open(Filename:=APExcellFilePath)
        Set ws1 = wb1.Sheets(1)
        RowCount1 = ws1.UsedRange.Rows.Count
        ColumnCount1 = ws1.UsedRange.Columns.Count
        APmyArray = ws1.Range("A1:U" & ColumnCount1).Value
        wb1.Close SaveChanges:=False
        Set wb1 = Nothing
        
        Set wb2 = Workbooks.Open(Filename:=BOExcellFilePath)
        Set ws2 = wb2.Sheets(1)
        RowCount2 = ws2.UsedRange.Rows.Count
        ColumnCount2 = ws2.UsedRange.Columns.Count
        BOmyArray = ws2.Range("A1:Y" & ColumnCount2).Value
    
        For i = 1 To RowCount2
        TempValue = 0
            For j = 2 To RowCount1
                If (APmyArray(j, 5) = BOmyArray(i, 3)) Then
                  If (BOmyArray(i, 10) = "BUY") Then
                      If (APmyArray(i + 1, 15) <> "") Then
                          TempValue = APmyArray(i + 1, 15) + APmyArray(i + 1, 15) * 0.01
                          If (TempValue < BOmyArray(i, 12)) Then
                              ws2.Activate
                              ws2.Cells(i, 12).Value = TempValue
                          End If
                      End If
                  ElseIf (BOmyArray(i, 10) = "SELL") Then
                      If (APmyArray(i + 1, 15) <> "") Then
                          TempValue = APmyArray(i + 1, 15) - APmyArray(i + 1, 15) * 0.01
                          If (TempValue > BOmyArray(i, 12)) Then
                              ws2.Activate
                              ws2.Cells(i, 12).Value = TempValue
                          End If
                      End If
                  End If
                End If
            Next
        Next
        Application.ScreenUpdating = True
        wb2.Save
        wb2.Close
    End Sub
    Attached Files Attached Files

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
  •