Compare values from two or more sheets, leave only non repeated values

reynierpm

New Member
Joined
Mar 21, 2013
Messages
1
Hi, I've two sheets with values, each sheet have only one column but with a lot of rows. I need to get only the values from the second sheet that aren't on the first one and write them into a new sheet. For that I build this code:

PHP:
Sub Button1_Click()
    Dim i As Long
    Dim j As Long
    Dim k As Long
    
    Dim number1 As Double
    Dim number2 As Double
    
    Dim numbers() As Double
    
    Dim rows1 As Long
    Dim rows2 As Long
    Dim rows3 As Long
    
    rows1 = Worksheets("bl_db").UsedRange.Rows.Count
    rows2 = Worksheets("cm_db").UsedRange.Rows.Count
    rows3 = Worksheets("new_db").UsedRange.Rows.Count

    Worksheets("dbmanuel-clanmovil-blacklist").Cells(1, "A").Value = "Números en Base - Lista Negra"
    Worksheets("dbmanuel-clanmovil-blacklist").Cells(2, "A").Value = "Números en Base - Clan Movil"
    Worksheets("dbmanuel-clanmovil-blacklist").Cells(3, "A").Value = "Números en Base - BD Nueva (Manuel)"
    
    Worksheets("dbmanuel-clanmovil-blacklist").Cells(1, "B").Value = rows1
    Worksheets("dbmanuel-clanmovil-blacklist").Cells(2, "B").Value = rows2
    Worksheets("dbmanuel-clanmovil-blacklist").Cells(3, "B").Value = rows3

    k = 5

    'strText = InputBox("Enter a song name:")

    For i = 1 To rows1
        number1 = Worksheets("bl_db").Cells(i, "A").Value
        For j = 1 To rows2
            number2 = Worksheets("cm_db").Cells(j, "A").Value
            If (number1 <> number2) Then
                If (Left(number2, 1) = "0") Then
                    number2 = Right(number2, 10)
                ElseIf (Left(number2, 2) = "58") Then
                    number2 = Right(number2, 10)
                End If
                              
                If (k <> 1048576) Then
                    Worksheets("dbmanuel-clanmovil-blacklist").Cells(k, "A").Value = number2
                Else
                    Worksheets("dbmanuel-clanmovil-blacklist").Cells(k, "B").Value = number2
                End If
                k = k + 1
            End If
        Next j
    Next i
        
End Sub

When values reach 1048576 then I got a error so I need to move to a new sheet dinamically or to a new column inside the same sheet. Can any help me on this?
 

Excel Facts

Fastest way to copy a worksheet?
Hold down the Ctrl key while dragging tab for Sheet1 to the right. Excel will make a copy of the worksheet.

Forum statistics

Threads
1,202,990
Messages
6,052,948
Members
444,620
Latest member
marialewis16

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