Vba copy and paste filtered sorted data in new sheet

mark84

New Member
Joined
Jan 22, 2021
Messages
29
Office Version
  1. 2016
Platform
  1. Windows
Hello,
I d want your support to solve this work.
I have a file named "Test Ven".
I tried to write a part of vba but it doesn't work.
I need a macro to automate these steps:
1) order all data for column B from A to Z
2) Then order these data for column C from the smallest to the greatest.
3) Filter for column Bfor the criteria "HP"
4) Copy and paste in column A of the new sheet named "Work1" filtered values of the columns A, C, D, E, F, G, H.
5) Then come back on the sheet "Test Ven" and filter for column B for the criteria "MP"
6) Copy and paste in "Work1" sheet after column G, filtered values of the columns G, H
7) Then come back on the sheet "Test Ven" and filter for column B for the criteria "GI"
8) Copy and paste in "Work1" sheet after column I, filtered values of the columns G, H
9) Then come back on the sheet "Test Ven" and filter for column B for the criteria "VS"
10) Copy and paste in "Work1" sheet after column K, filtered values of the columns G, H, J

Thanks so much for your support!

Mark
 

Attachments

  • test ven.PNG
    test ven.PNG
    58.3 KB · Views: 36

Excel Facts

Difference between two dates
Secret function! Use =DATEDIF(A2,B2,"Y")&" years"&=DATEDIF(A2,B2,"YM")&" months"&=DATEDIF(A2,B2,"MD")&" days"
How about
VBA Code:
Sub mark()
   Dim Ary As Variant
   Dim i As Long
   
   Ary = Array("HP", "A1", "A:H", "MP", "I1", "G:H", "GI", "K1", "G:H", "VS", "M1", "G:J")
   With Sheets("Test Ven")
      .Range("a1").CurrentRegion.Sort .Range("B1"), xlAscending, .Range("C1"), , xlAscending, , , xlYes
      For i = 0 To UBound(Ary) Step 3
         .Range("A1:J1").AutoFilter 2, Ary(i)
         .AutoFilter.Range.Offset(1).Columns(Ary(i + 2)).Copy Sheets("Work1").Range(Ary(i + 1))
      Next i
      .AutoFilterMode = False
   End With
   Sheets("Work1").Range("B:B,O:O").EntireColumn.Delete
End Sub
This assumes that the Work1 sheet already exists
 
Upvote 0
Thank you! It's perfect and works well!

Have a nice day

Mark
 
Upvote 0
You're welcome & thanks for the feedback.
 
Upvote 0

Forum statistics

Threads
1,214,804
Messages
6,121,652
Members
449,045
Latest member
Marcus05

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