aayaanmayank

Board Regular
Joined
Jul 20, 2018
Messages
156
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

Shade all formula cells
To shade all formula cells: Home, Find & Select, Formulas to select all formulas. Then apply a light fill color.

BarryL

Well-known Member
Joined
Jan 20, 2014
Messages
1,436
Office Version
  1. 2019
Platform
  1. Windows
  2. MacOS
where are the outputs going to? different sheets?

Need more information for this, expected result sample would be nice.
 

BarryL

Well-known Member
Joined
Jan 20, 2014
Messages
1,436
Office Version
  1. 2019
Platform
  1. Windows
  2. MacOS
so why not copy everything in (no loop) and sort by ID/date?
 

aayaanmayank

Board Regular
Joined
Jul 20, 2018
Messages
156

ADVERTISEMENT

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.
 

BarryL

Well-known Member
Joined
Jan 20, 2014
Messages
1,436
Office Version
  1. 2019
Platform
  1. Windows
  2. MacOS
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
 

BarryL

Well-known Member
Joined
Jan 20, 2014
Messages
1,436
Office Version
  1. 2019
Platform
  1. Windows
  2. MacOS
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
 

Forum statistics

Threads
1,136,341
Messages
5,675,206
Members
419,553
Latest member
hanahass

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
Top