Quantcast
Channel: Excel IT Pro Discussions forum
Viewing all articles
Browse latest Browse all 11829

Column comparision in Excel using VBA

$
0
0

Hi,

I have written a VBA code that matches the 1st column with sencond column and return the entries of 1st row  that are not available in second row.Given below is the sample code which i used in My script..Now the problem is mathching of columns not happening correctly,some matched values are also coming in the output.Someone please help me to find where i am incorrect.

Dim c As Range, d As Range
    Dim LastRow1 As Integer
    Dim LastRow2 As Integer
    Dim rng1 As Range, rng2 As Range, rng3 As Range
    
    shPort_Code.Activate
    LastRow1 = Cells(Rows.Count, "B").End(xlUp).Row
    LastRow2 = Cells(Rows.Count, "J").End(xlUp).Row
    
    For i = 4 To LastRow1
        Set rng1 = shPort_Code.Range("B" & i)
        
        For j = 2 To LastRow2
            Set rng2 = shPort_Code.Range("J" & j)
            'If rng1.Text='
            If StrComp(rng1.Text, rng2.Text, 1) = 0 Then
            
                'rng1.Cells("D" & i).Value.Copy Destination:=shPort_Code.Range("J2")
                rng1.Value = Null
            'Else
                'rng1.Text.Select
            End If
        Next j
        If Not Match Then
            Range("J" & Range("J" & Rows.Count).End(xlUp).Row + 1) = rng1
        End If
    Next i

Thanks in advance.

Renu



Viewing all articles
Browse latest Browse all 11829

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>