Excel Copy Unique Values To Other Sheet

Excel VBA Copy Unique Values


           In our template , unique values in Column A are found with VBA codes :
With Sheets("Sheet1")
    .Range("A1:A" & .Cells(Rows.Count, 1).End(xlUp).Row).AdvancedFilter Action:=xlFilterInPlace, Unique:=True
...
End With

Later ,the found unique values in Column A are copied and listed in Column A of the other worksheet :
With Sheets("Sheet1")
...
  .Range("A1:A" & .Cells(Rows.Count, 1).End(xlUp).Row).Copy Sheets("Sheet2").Range("A1")
  .ShowAllData
End With


excel vba copy unique values

All of the VBA codes in Module1:
Sub Unlikecopy()
With Sheets("Sheet1")
    .Range("A1:A" & .Cells(Rows.Count, 1).End(xlUp).Row).AdvancedFilter Action:=xlFilterInPlace, Unique:=True
    .Range("A1:A" & .Cells(Rows.Count, 1).End(xlUp).Row).Copy Sheets("Sheet2").Range("A1")
    .ShowAllData
End With
End Sub

The following codes are used to call the Unlikecopy () procedure with the button in Sheet1:
Private Sub CommandButton1_Click()
Call Unlikecopy
End Sub


excel vba copy unique values

No comments:

Post a Comment