aayaanmayank

Board Regular
Joined
Jul 20, 2018
Messages
157
Hi i have to apply filter then select one ID at one time then copy dates for the particular ID . then again select next id and repeat the same task till the last ID.

IDEarly Start
ABCXXXXZZZZ1-Aug-17
ABCXXXXZZZZ1-Aug-17
ABCXXXXZZZZ1-Aug-17
KOP1-Aug-17
ABH1-Aug-17
ABCXXXXZZZZ1-Aug-17
IKLPOYL1-Aug-17
RAHUOP1-Aug-17
ABCXXXXZZZZ1-Aug-17
WASPOCD1-Aug-17
ABCXXXXZZZZ1-Aug-17
ABCXXXXZZZZ1-Aug-17
ABCXXXXZZZZ1-Aug-17
ABCXXXXZZZZ1-Aug-17
ABCXXXXZZZZ1-Aug-17
ABCXXXXZZZZ1-Aug-17
ABCXXXXZZZZ1-Aug-17
98KOP051-Aug-17

<colgroup><col><col></colgroup><tbody>
</tbody>
 

Excel Facts

Do you hate GETPIVOTDATA?
Prevent GETPIVOTDATA. Select inside a PivotTable. In the Analyze tab of the ribbon, open the dropown next to Options and turn it off
where are the outputs going to? different sheets?

Need more information for this, expected result sample would be nice.
 
Upvote 0
so why not copy everything in (no loop) and sort by ID/date?
 
Upvote 0
Hi I have just given the sample data. Rest there are are multiple things which i have to do. Hence i only need support to filter one by one each id and copy the date and paste data.
 
Upvote 0
you didnt give expected results. try the below. it will copy the data over. it pastes in sheet1 X1. if you have data there change those references.

Code:
Sub test()
Dim sh As Worksheet, ws As Worksheet
    Set sh = Sheets("Sheet1")
    Set ws = Sheets("Sheet2")
        sh.Range("A1:A" & sh.Range("A" & Rows.Count).End(xlUp).Row).AdvancedFilter Action:=xlFilterCopy, CopyToRange:=sh.Range("X1"), Unique:=True
        
Dim rng As Range
    If sh.AutoFilterMode = True Then sh.AutoFilterMode = False
    For Each rng In sh.Range("X2:X" & sh.Range("X" & Rows.Count).End(xlUp).Row)
        sh.Range("A1:B" & sh.Range("A" & Rows.Count).End(xlUp).Row).AutoFilter 1, rng.Value
        sh.Range("A2:B" & sh.Range("A" & Rows.Count).End(xlUp).Row).SpecialCells(xlCellTypeVisible).Copy ws.Range("A" & Sheet2.Range("A" & Rows.Count).End(xlUp).Row + 1)
        sh.AutoFilterMode = False
Next
End Sub
 
Upvote 0
needed to change one thing on the above

Code:
Sub test()
Dim sh As Worksheet, ws As Worksheet
    Set sh = Sheets("Sheet1")
    Set ws = Sheets("Sheet2")
        sh.Range("A1:A" & sh.Range("A" & Rows.Count).End(xlUp).Row).AdvancedFilter Action:=xlFilterCopy, CopyToRange:=sh.Range("X1"), Unique:=True
        
Dim rng As Range
    If sh.AutoFilterMode = True Then sh.AutoFilterMode = False
    For Each rng In sh.Range("X2:X" & sh.Range("X" & Rows.Count).End(xlUp).Row)
        sh.Range("A1:B" & sh.Range("A" & Rows.Count).End(xlUp).Row).AutoFilter 1, rng.Value
        sh.Range("A2:B" & sh.Range("A" & Rows.Count).End(xlUp).Row).SpecialCells(xlCellTypeVisible).Copy ws.Range("A" & ws.Range("A" & Rows.Count).End(xlUp).Row + 1)
        sh.AutoFilterMode = False
Next
End Sub
 
Upvote 0

Forum statistics

Threads
1,213,549
Messages
6,114,264
Members
448,558
Latest member
aivin

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