View Single Post
 
Old 06-11-2014, 11:35 PM
mavCZ mavCZ is offline Windows 7 64bit Office 2013
Novice
 
Join Date: Jun 2014
Posts: 1
mavCZ is on a distinguished road
Default Slow "comparison/replace" script

Hi everyone, this script is supposed to compare two ranges and in case of no match replace cells with text. Im quite new to VBA and when I usually write a script, it performs poorly on big data sets. Is there any way, how to make this work faster? I have tried Application.ScreenUpdating = False, but it doesnt work.

Thank you in advance!


Code:
Sub RangeCompare()
    Dim Range1 As Range, Range2 As Range, c As Range
    
    On Error Resume Next
    
    Set Range1 = ActiveWorkbook.Sheets("Master Slide").Range("a4:a90")
    Set Range2 = Application.InputBox("Select Range2:", Title:="Get Range2", Type:=8)
       
    On Error GoTo 0
    
    For Each c In Range2.Cells
    
    If Len(c) > 0 Then
        If Application.WorksheetFunction.CountIf(Range1, c.Value) = 0 Then
            c.Formula = "Others"
        End If
    End If
        
    Next c
        
End Sub
Reply With Quote