use VBA to auto-filter and copy filtered data to another sheet

Eliehaddad

New Member
Joined
May 25, 2018
Messages
10
Hello,

please i need you assistance to automaticaly filter data in a specific table based on the customer name and copy the filtered data related to this customer to another worksheet using VBA

example: i need to automaticaly filter the projects by the name of the project owner and autocopy the related data of the projects to another sheet.

[TABLE="width: 500"]
<tbody>[TR]
[TD]project name[/TD]
[TD]decsription[/TD]
[TD]project owner[/TD]
[/TR]
[TR]
[TD]mars[/TD]
[TD]XXX[/TD]
[TD]Sam[/TD]
[/TR]
[TR]
[TD]venus[/TD]
[TD]YYY[/TD]
[TD]Mark[/TD]
[/TR]
[TR]
[TD]earth[/TD]
[TD]ZZZ[/TD]
[TD]Sam[/TD]
[/TR]
</tbody>[/TABLE]

so will have this result in the 2nd sheet

[TABLE="width: 500"]
<tbody>[TR]
[TD]project name[/TD]
[TD]decsription[/TD]
[TD]project owner[/TD]
[/TR]
[TR]
[TD]mars[/TD]
[TD]XXX[/TD]
[TD]Sam[/TD]
[/TR]
[TR]
[TD]earth[/TD]
[TD]ZZZ[/TD]
[TD]Sam[/TD]
[/TR]
</tbody>[/TABLE]


thank you in advance :)
 
Ok, try this
Code:
Sub MoveDupes()
   Dim ws As Worksheet
   Dim Cl As Range
   Dim sht As Worksheet
   
   For Each sht In Sheets(Array([COLOR=#ff0000]"Joseph", "Nihale", "Lea"[/COLOR]))
      sht.Range("A5:A" & Rows.Count).EntireRow.Clear
   Next sht
   Set ws = Sheets("Report")
   If ws.AutoFilterMode Then ws.AutoFilterMode = False
   With CreateObject("scripting.dictionary")
      For Each Cl In ws.Range("C5", ws.Range("C" & Rows.Count).End(xlUp))
         If Not .exists(Cl.Value) And Cl.Value <> 0 Then
            .Add Cl.Value, Nothing
            ws.Range("A4").AutoFilter 3, Cl.Value
            ws.AutoFilter.Range.Offset(1).Copy Sheets(Split(Cl.Value)(0)).Range("A" & Rows.Count).End(xlUp).Offset(1)
         End If
      Next Cl
   End With
   ws.AutoFilterMode = False
End Sub
If you have more Project Owners add them to the array in red
 
Upvote 0

Excel Facts

Square and cube roots
The =SQRT(25) is a square root. For a cube root, use =125^(1/3). For a fourth root, use =625^(1/4).
Glad we could help & thanks for the feedback
 
Upvote 0

Forum statistics

Threads
1,223,910
Messages
6,175,318
Members
452,634
Latest member
cpostell

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