Checking if defined pairs of values exists in big range - performance issue

balth

New Member
Joined
Nov 9, 2016
Messages
1
Hello,

I have been reading this forum for a long time and so many times was able to find solutions to the challenges I was facing so thank you all for all your contributions!

However finally came to the the point where I had to register to write the first post as I am struggling with one of the macros I have put together.

In general for each cell in column Y I need to check if there is at least one row in the spreadsheet where value in column A is the same as value in column A in the row where the cell is, and the value in column J is "yes".

I have adjusted some code I have came across online and it seems that it is working for short ranges. Unfortunately I have more than 100000 rows in the spreadsheet and this is just killing the macro.

Pasting the code below. Could you please advise me how can I make it more efficient?

Sub Macro1()

On Error Resume Next


Application.Calculation = xlCalculationManual
Application.ScreenUpdating = False
Application.DisplayStatusBar = False
Application.EnableEvents = False


Dim rng As Range, cell As Range
Dim FindString As String
Dim rng2 As Range
Dim count As Long
Dim myRow As Range

Set rng = Sheets("Sheet1").Range("Y2:Y100000")

For Each cell In rng
count = 0
FindString = cell.Offset(0, -24).Value

For Each myRow In Range("A2:X100000").Rows

If myRow.Cells(1, 10).Value = "yes" And myRow.Cells(1, 1).Value = FindString Then

count = count + 1

End If

If count > 0 Then Exit For

Next myRow

If count > 0 Then
cell.Value = "yes"
Else
cell.Value = "no"

End If

Next cell

Application.Calculation = xlCalculationAutomatic
Application.ScreenUpdating = True
Application.DisplayStatusBar = True
Application.EnableEvents = True


End Sub


Thank you in advance!
 

Excel Facts

Did you know Excel offers Filter by Selection?
Add the AutoFilter icon to the Quick Access Toolbar. Select a cell containing Apple, click AutoFilter, and you will get all rows with Apple

Forum statistics

Threads
1,221,310
Messages
6,159,176
Members
451,543
Latest member
cesymcox

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top