Compare Data in Two Ranges Row by Row and Count Matches

Steviemac

New Member
Joined
May 24, 2021
Messages
14
Office Version
  1. 2019
Platform
  1. Windows
Hi there, first time poster, long time lurker

Hoping some kind soul can speed up this macro with a light speed modification

The data to check (InputData) is replaced many times at this part of the process and at the rate the InputData comes in is
proving to be a real bottleneck, the macro works fine, it's just that it takes 16 seconds to run each time, which is too long
Hopefully there is a better faster way (maybe a macro rewrite!)

Data is held in two data sets, both 5 columns across
InputData set is 56 rows (variable)
TaskPercentComplete set is 2000 rows (variable)

Every row in the 'InputData' table is compared with Each row in turn in the 'TaskPercentComplete' table
for matches - it only has to record whether there is a match of 3 values and/or a match of 4 values

Any help is very much appreciated

Thanks Ste


VBA Code:
Sub TaskPercentages()

Application.ScreenUpdating = False

Dim InputData As Long

Sheets("TaskPercentComplete").Range("J3:L10000").ClearContents

 InputData = 2
 
   Do While Not Sheets("TaskPercentComplete").Cells(InputData, 46).Value = ""
  
       TaskDataOutput = 3
                 
        Do While Not Sheets("TaskPercentComplete").Cells(TaskDataOutput, 3).Value = ""
       
            Dim rngA As Range: Set rngA = Range("C" & TaskDataOutput & ":G" & TaskDataOutput)
            Dim rngB As Range: Set rngB = Range("AT" & InputData & ":AX" & InputData)

            If Evaluate("SUMPRODUCT(COUNTIF(" & rngA.Address & "," & rngB.Address & "))") = 4 Then
            Sheets("TaskPercentComplete").Cells(TaskDataOutput, 11).Value = "80%"
            End If
           
            If Evaluate("SUMPRODUCT(COUNTIF(" & rngA.Address & "," & rngB.Address & "))") = 3 Then
            Sheets("TaskPercentComplete").Cells(TaskDataOutput, 10).Value = "60%"
            End If

        TaskDataOutput = (TaskDataOutput + 1)
     
       Loop
   
      InputData = (InputData + 1)
  
   Loop
  
  'nextonwardmacro
 
End Sub
 
Fluff, you nailed it - it must have been a corrupted sheet or something, rebuilding it fixed it

Don't know what it was but its now perfect

You are the man

Nice one mate, a big thanks on this one

Ste
 
Upvote 0

Excel Facts

What does custom number format of ;;; mean?
Three semi-colons will hide the value in the cell. Although most people use white font instead.
Glad it's sorted & thanks for the feedback.
 
Upvote 0
Ok, how about
VBA Code:
Sub Steviemac()
   Dim Iary As Variant, Oary As Variant, Nary As Variant
   Dim r As Long, c As Long, rr As Long, cc As Long, i As Long
   
   With Sheets("TaskPercentComplete")
      Iary = .Range("AT2:AX" & .Range("AT" & Rows.Count).End(xlUp).Row).Value2
      Oary = .Range("C3:G" & .Range("C" & Rows.Count).End(xlUp).Row).Value2
   End With
   ReDim Nary(1 To UBound(Oary), 1 To 2)
   
   For r = 1 To UBound(Iary)
      For rr = 1 To UBound(Oary)
         For c = 1 To 5
            For cc = 1 To 5
               If Iary(r, c) = Oary(rr, cc) Then i = i + 1
            Next cc
         Next c
         If i = 3 Then Nary(rr, 1) = "60%"
         If i = 4 Then Nary(rr, 2) = "80%"
         i = 0
      Next rr
   Next r
   Sheets("TaskPercentComplete").Range("J3").Resize(UBound(Oary), 2).Value = Nary
End Sub
 
Upvote 0
Solution
Glad to help & thanks for the feedback.
 
Upvote 0

Forum statistics

Threads
1,215,066
Messages
6,122,948
Members
449,095
Latest member
nmaske

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