Most compact/efficient VBA to do this?

chuckles1066

Banned
Joined
Dec 20, 2004
Messages
372
I can do some of this via the macro recorder but it seems to insert all sorts of random, seemingly irrelevant lines of code.

Columns A-G contain data, the number of rows changes from month to month.

I need to sort based on column G (ascending) and then column F (descending).

I then need to run through the data, grabbing the top 20 values in column F for each of four values in column G.

This data is then pasted into columns J and K.

Column G contains either East, North, South or West.

To clarify; having sorted on column G and then F, the top x rows will be for East with the highest at the top so it's a simple matter to grab the top 20 (rows 2-21).

But then I need to identify where the last value for East ends and the first value for North begins and then grab the top 20.

And so on.

Any takers?

TIA.
 

Excel Facts

How to create a cell-sized chart?
Tiny charts, called Sparklines, were added to Excel 2010. Look for Sparklines on the Insert tab.
In your macro, I would sort the entire columns on G & F. That code will hold no matter how long the numbers. I would then start at your first item in the list. "IF" it equals "East", I would offset one cell right, capture the cell value, then move another cell right, and paste the value. Then offset back to the original, offset down one, and so on until you loop out of "east", then move on to looking for North, and so on.
 
Upvote 0

Forum statistics

Threads
1,224,585
Messages
6,179,704
Members
452,938
Latest member
babeneker

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