VBA to copy Filtered top 10 data to another sheet

Turbo68

Board Regular
Joined
Jan 31, 2014
Messages
118
I have this started with doing some google searches and the below code works but it is copying the wrong col in my original:

'Copy Sorted TOP 10

Dim i As Long
Dim r As Range
Dim rWC As Range

Set r = Range("D16", Range("D" & Rows.Count).End(xlUp)).SpecialCells(10)

For Each rWC In r
i = i + 1
If i = 10 Or i = r.Count Then Exit For
Next rWC
Range(r(1), rWC).Resize(, 10).SpecialCells(10).Copy


Sheets("Division TOP-BOTTOM 10").Select
Range("TOP_10").Select
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False

My Data looks like this:

1588651362977.png


As you can see the A is St#, B is Area, C is blank, D is the COL i want it to highlight the top 10 entries. Right now the code i am using is highlighing this:

1588651409838.png


It is not selecting the visiable cells but it is selecting 10 cells but selecting A and B col and not D either! I thought i had r= row D in the setup but not a clue why its not selcting correctly.

Major confusion here... :)

Any help is much appreciated.

Mike
 

Attachments

  • 1588650923567.png
    1588650923567.png
    28.4 KB · Views: 3
  • 1588651074256.png
    1588651074256.png
    27.2 KB · Views: 1

Excel Facts

Save Often
If you start asking yourself if now is a good time to save your Excel workbook, the answer is Yes
What are you trying to do with this line?
VBA Code:
Set r = Range("D16", Range("D" & Rows.Count).End(xlUp)).SpecialCells(10)
 
Upvote 0
The code I found had that line in there. It made sense to me as to pointing the data that I needed. But, I don't follow it myself. It does specify the 10 lines of data that i need.

Mike
 
Upvote 0
That line of code is pointing to dependant cells.
Change the 10 to 12 on that line & the other specialcells line.
 
Upvote 0
Now the selection is this:

1588700705514.png


This is what i am needing it to select:

1588700759008.png


Maybe I have the total wrong coding? arrrggg

Mike
 
Upvote 0
I thought you wanted the top 10 visible rows from column D. If that is not the case, then please clearly explain exactly what you do want.
 
Upvote 0
Sorry to be confusing:

1588704403825.png


As you see here... i am looking for the top 10 in col D to copy:

1588704519679.png


Is that better?

M
 
Upvote 0
If you made the 2 changes I suggested, it should do that.
Can you please post your current code?
 
Upvote 0

Forum statistics

Threads
1,216,105
Messages
6,128,861
Members
449,472
Latest member
ebc9

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