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




Reply With Quote

Bookmarks