Sub STEP7()
Dim Wbap As Workbook
Set Wbap = Workbooks.Open("C:UsersWolfieeeStyleDesktopap.xls")
Dim Wsap As Worksheet
Set Wsap = Wbap.Worksheets.Item(1)
Dim Lrap As Long: Let Lrap = Wsap.Range("B" & Wsap.Rows.Count & "").End(xlUp).Row
Dim Arrap As Variant: Let Arrap = Wsap.Range("A1:Y" & Lrap & "").Value2
Dim arrH2pc() As Variant, arrI2pc() As Variant
Let arrH2pc() = Evaluate("=2/100*H2:H" & Lrap & "")
Let arrI2pc() = Evaluate("=2/100*I2:I" & Lrap & "")
Rem 2
Dim arrS() As Variant: Let arrS() = Wsap.Range("S1:S" & Lrap & "").Value2
Dim arrU() As Variant: Let arrU() = Wsap.Range("U1:U" & Lrap & "").Value2
Dim Cnt As Long
For Cnt = 2 To Lrap
If arrS(Cnt, 1) >= 0 Then
Dim BgstHI As Double
Let BgstHI = arrH2pc(Cnt - 1, 1) ' Cnt - 1 is because our arrays for the H and I columns start at row 2 , so the indices will be one less than the roe to which they apply . I chose to do this to avoid trying to get 2% of the header , as that would error
If arrH2pc(Cnt - 1, 1) < arrI2pc(Cnt - 1, 1) Then Let BgstHI = arrI2pc(Cnt - 1, 1) ' If I column is largest, use that, otherwise H will be taken NOTE: H will be taken if the H and I columnns are equal
If arrS(Cnt, 1) < BgstHI Then Let arrU(Cnt, 1) = -1
Else ' S < 0
' column S should be positive, so don’t considere the no. which are negative
End If
Next Cnt
Rem 3 paste out
Let Wsap.Range("S1:S" & Lrap & "").Value2 = arrU()
Wbap.Save
Wbap.Close
End Sub
I am getting error with this macro plz see the sample pic
& when i run the macro it paste the result as -1 & I need, it should paste the result as A only
Sub STEP7()
Dim Wbap As Workbook
Set Wbap = Workbooks.Open("C:UsersWolfieeeStyleDesktopap.xls")
Dim Wsap As Worksheet
Set Wsap = Wbap.Worksheets.Item(1)
Dim Lrap As Long: Let Lrap = Wsap.Range("B" & Wsap.Rows.Count & "").End(xlUp).Row
Dim Arrap As Variant: Let Arrap = Wsap.Range("A1:Y" & Lrap & "").Value2
Dim arrH2pc As Variant, arrI2pc As Variant
Let arrH2pc = Evaluate("=2/100*H1:H" & Lrap & "")
Let arrI2pc = Evaluate("=2/100*I1:I" & Lrap & "")
Rem 2
Dim arrS() As Variant: Let arrS() = Wsap.Range("S1:S" & Lrap & "").Value2
Dim arrU() As Variant: Let arrU() = Wsap.Range("U1:U" & Lrap & "").Value2
Dim Cnt As Long
For Cnt = 2 To Lrap
If arrS(Cnt, 1) >= 0 Then
Dim BgstHI As Double
Let BgstHI = arrH2pc(Cnt, 1) ' Cnt - 1 is because our arrays for the H and I columns start at row 2 , so the indices will be one less than the roe to which they apply . I chose to do this to avoid trying to get 2% of the header , as that would error
If arrH2pc(Cnt, 1) < arrI2pc(Cnt, 1) Then Let BgstHI = arrI2pc(Cnt, 1) ' If I column is largest, use that, otherwise H will be taken NOTE: H will be taken if the H and I columnns are equal
If arrS(Cnt, 1) < BgstHI Then Let arrU(Cnt, 1) = -1
Else ' S < 0
' column S should be positive, so don’t considere the no. which are negative
End If
Next Cnt
Rem 3 paste out
Let Wsap.Range("S1:S" & Lrap & "").Value2 = arrU()
Wbap.Save
Wbap.Close
End Sub
If arrS(Cnt, 1) < BgstHI Then Let arrU(Cnt, 1) = "A"
I changed this line bcoz i need result as A & i ran the code , the code is doing perfect job & i let u know about the changes that i made, so plz let me know this will not affect anything correct?