Vba copy and paste filtered sorted data in new sheet

mark84

New Member
Joined
Jan 22, 2021
Messages
5
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: 13

Excel Facts

Create a chart in one keystroke
Select the data and press Alt+F1 to insert a default chart. You can change the default chart to any chart type

Fluff

MrExcel MVP, Moderator
Joined
Jun 12, 2014
Messages
56,614
Office Version
  1. 365
Platform
  1. Windows
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
 

mark84

New Member
Joined
Jan 22, 2021
Messages
5
Office Version
  1. 2016
Platform
  1. Windows
Thank you! It's perfect and works well!

Have a nice day

Mark
 

Fluff

MrExcel MVP, Moderator
Joined
Jun 12, 2014
Messages
56,614
Office Version
  1. 365
Platform
  1. Windows
You're welcome & thanks for the feedback.
 

Watch MrExcel Video

Forum statistics

Threads
1,129,685
Messages
5,637,809
Members
416,983
Latest member
LessThanAverageUser

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