match formula in for loop OPTIMISATION

jaik22

Board Regular
Code:
`````` Lastrow = ActiveSheet.UsedRange.SpecialCells(xlCellTypeLastCell).Row
For i = 3 To Lastrow

Sheets("sample").Range("AM1000000").End(xlUp).Offset(1, 0).Select
Selection.FormulaArray = _
"=IF(ISNUMBER(MATCH(1," & Chr(10) & "  (order!R2C15:R1000000C15=RC[-24])*" & Chr(10) & "  (order!R2C7:R1000000C7=RC[-32])*" & Chr(10) & "  (order!R2C24:R1000000C24=RC[-15])," & Chr(10) & "  0)), ""pass"",""review"")"

Next i
Columns("AM:AM").Select
Selection.Copy
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False``````

I am using match formula inside of for loop, but it is taking too much time. Is there any way to optimize this code to make it go faster?

Thank you!

footoo

Well-known Member
Code:
``````Dim rng As Range
Lastrow = ActiveSheet.UsedRange.SpecialCells(xlCellTypeLastCell).Row
With Sheets("Sample")
Set rng = .Range(.Range("AM1000000").End(xlUp).Offset(1, 0), .Range("AM" & Lastrow-2))
End With
rng.FormulaArray = "=IF(ISNUMBER(MATCH(1," & Chr(10) & "  (order!R2C15:R1000000C15=RC[-24])*" _
& Chr(10) & "  (order!R2C7:R1000000C7=RC[-32])*" & Chr(10) & _
"  (order!R2C24:R1000000C24=RC[-15])," & Chr(10) & "  0)), ""pass"",""review"")"
rng = rng.Value``````
Re this line :
Lastrow = ActiveSheet.UsedRange.SpecialCells(xlCellTypeLastCell).Row

Are you looking for the last row containing data?
If so, this is not a good way - it might return a row far beyond the last data row.
Is there a column that could be used to find the last data row?

Last edited:

jaik22

Board Regular
Thanks for the reply, but this code gives me only result for the first line. Is there any way to fix this?

Thanks!

footoo

Well-known Member
Step through via F8 to see what each line is doing and what is being assigned to the variables.

1,081,530
Messages
5,359,347
Members
400,524
Latest member
Excelbat

This Week's Hot Topics

• VBA (Userform)
Hi All, I just would like to know why my code isn't working. Here is my VBA code: [CODE=vba]Private Sub OKButton_Click() Dim i As Integer...
• List box that changes fill color
Hello, I have gone through so many pages trying to figure this out. I have a 2020 calendar that depending on the day needs to have a certain...
• Remove duplicates and retain one. Cross-linked cases
Hi all I ran out of google keywords to use and still couldn't find a reference how to achieve the results of a single count. It would be great if...
• VBA Copy and Paste With Duplicates
Hello All, I'm in need of some input. My VBA skills are sub-par at best. I've assembled this code from basic research and it works but is...
• Macro
is it possible for a macro to run if the active cell value is different to the value above it
• IF DATE and TIME
I currently use this to check if date has passed but i also need to set a time on it too. Is it possible? [CODE=vba]=IF(B:B>TODAY(),"Not...