2 Attachment(s)
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
2 Attachment(s)
Clear the data if matches
https://www.excelforum.com/excel-pro...f-matches.html
Hi,
I am looking for a macro that doesnt the things mentioned below
If column E of book1.xlsb matches with column Z of ap.xls & column U of ap.xls is postive then match column Z of ap.xls with column B of sheet1 of book1.xlsb & if it matches then clear the data in sheet1 of book1.xlsb
macro will be placed in book1.xlsb so the path should be hardcoded in the macro
clear the data means we have to clear the data from column C of sheet1 of book1.xlsb (we dont have to delete the data of column A & Column B of sheet1 of book1.xlsb )
Thnx For the Help