How to create macro to search and copy
Closed
lineoff38
Posts
1
Registration date
Saturday March 20, 2010
Status
Member
Last seen
March 20, 2010
-
Mar 20, 2010 at 02:22 PM
venkat1926 Posts 1863 Registration date Sunday June 14, 2009 Status Contributor Last seen August 7, 2021 - Mar 21, 2010 at 01:11 AM
venkat1926 Posts 1863 Registration date Sunday June 14, 2009 Status Contributor Last seen August 7, 2021 - Mar 21, 2010 at 01:11 AM
Related:
- How to create macro to search and copy
- How to create @ in laptop - Guide
- How to search for words on websites - Guide
- How to search nearby friends on facebook - Guide
- How to remove search baron - Guide
- How to create instagram story on laptop - Guide
1 response
venkat1926
Posts
1863
Registration date
Sunday June 14, 2009
Status
Contributor
Last seen
August 7, 2021
811
Mar 21, 2010 at 01:11 AM
Mar 21, 2010 at 01:11 AM
I am giving two macros "test" and "undo"
the sample sheet is like this (sheet1)-not necessary to sort
date data1 data2
3/1/2010 37 1
3/2/2010 65 96
3/3/2010 48 46
3/2/2010 78 54
3/5/2010 3 38
3/2/2010 83 58
3/3/2010 45 78
try the macro "test" and see sheet2
if you want retest
1.run "undo"
then
2.rung "test"
the macros are
the sample sheet is like this (sheet1)-not necessary to sort
date data1 data2
3/1/2010 37 1
3/2/2010 65 96
3/3/2010 48 46
3/2/2010 78 54
3/5/2010 3 38
3/2/2010 83 58
3/3/2010 45 78
try the macro "test" and see sheet2
if you want retest
1.run "undo"
then
2.rung "test"
the macros are
Sub test()
Dim r As Range, r1 As Range, r2 As Range
Dim c2 As Range, cfind As Range
Worksheets("sheet1").Activate
Set r = Range(Range("A1"), Range("A1").End(xlDown))
Set r1 = Range("a1").End(xlDown).Offset(5, 0)
r.AdvancedFilter action:=xlFilterCopy, copytorange:=r1, unique:=True
Set r2 = Range(r1.Offset(1, 0), r1.End(xlDown))
For Each c2 In r2
If WorksheetFunction.CountIf(r, c2) > 1 Then
With Range("A1").CurrentRegion
.AutoFilter field:=1, Criteria1:=c2.Value
.Cells.SpecialCells(xlCellTypeVisible).Copy
Worksheets("sheet2").Cells(Rows.Count, "A").End(xlUp).Offset(1, 0).PasteSpecial
End With
End If
ActiveSheet.AutoFilterMode = False
Next c2
Worksheets("sheet2").Activate
Do
Set cfind = ActiveSheet.Cells.Find(what:="date", lookat:=xlWhole, after:=Range("A2"))
If cfind Is Nothing Then Exit Do
cfind.EntireRow.Delete
Loop
Worksheets("sheet1").Range("A1").EntireRow.Copy
Worksheets("sheet2").Range("A1").PasteSpecial
Application.CutCopyMode = False
End Sub
Sub undo()
Worksheets("sheet2").Cells.Clear
End Sub