Excel VBA Copy Unique Values
With Sheets("Sheet1")
.Range("A1:A" & .Cells(Rows.Count, 1).End(xlUp).Row).AdvancedFilter Action:=xlFilterInPlace, Unique:=True
...
End With
.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
...
.Range("A1:A" & .Cells(Rows.Count, 1).End(xlUp).Row).Copy Sheets("Sheet2").Range("A1")
.ShowAllData
End With
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
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
Call Unlikecopy
End Sub
No comments:
Post a Comment