Results 1 to 9 of 9

Thread: Add and Sort

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1
    VBAX Regular
    Joined
    Nov 2018
    Posts
    75
    Location

    Add and Sort

    Hello,

    I have two list of number on two separate sheets. I am trying to figure out how to compare the two lists, add the numbers that are on list one that don't exist on list two to list two and finally sort them so they match. I have attached a workbook and this what I have so far:

    Sub Addsort()
    Dim rngCell As Range
    Dim lastrow As Long
    
    
        For Each rngCell In Worksheets("Sheet 1").Range("A2:A10001")
            If WorksheetFunction.CountIf(Worksheets("Sheet 2").Range("A2:A100001"), rngCell) = 0 Then
                lastrow = Worksheets("Sheet 2").Cells(Rows.Count, "A").End(xlUp).Row
                Worksheets("Sheet 2").Range("A2:A" & lastrow).Value = rngCell
            End If
        Next rngCell
       Sheets("Sheet 2").Range("A2", Range("A2").End(xlDown)).Sort Key1:=Range("A2"), Order1:=xlAscending, Header:=xlYes
    End Sub
    Thanks.
    Attached Files Attached Files

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •