Avatar of swjtx99
swjtx99
 asked on

Copy first 10 Cells in a column of filtered and sorted data to another sheet.

Trying to write VBA to copy first 10 cells of a filtered and sorted data-set that will change each time query is run so using row numbers doesn't work. I have an example workbook attached that hopefully clarifies the request.

Example.xlsx

VBA

Avatar of undefined
Last Comment
swjtx99

8/22/2022 - Mon
Martin Liss

Something like the following which copies visible rows.

Application.Worksheets("Sheet1").Rows("1:10").Copy Destination:=Worksheets("Sheet2").Range("A1")

Open in new window

ASKER CERTIFIED SOLUTION
Norie

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
swjtx99

ASKER
Thank for the responses.

Martin, I get a runtime error saying the copy and paste areas aren't the same size.

Norie, This works but I can't tell how I might add another column. For example, how would I modify this to also bring the "Type" (column A) to the Results sheet in column D?

Thanks!

swjtx99
Martin Liss

You should use Norie's code. It seems to work perfectly.
All of life is about relationships, and EE has made a viirtual community a real community. It lifts everyone's boat
William Peck
swjtx99

ASKER
Thank for the responses.

Martin, I get a runtime error saying the copy and paste areas aren't the same size.

Norie, This works but I can't tell how I might add another column. For example, how would I modify this to also bring the "Type" (column A) to the Results sheet in column D?......Never mind, I figured it out!

Thanks!

swjtx99
swjtx99

ASKER
Hi Norie, Actually, I didn't figure it out. Can you tell me how to modify this to grab additional columns?

Thanks,
swjtx99

ASKER
Hi Norie, Actually, I did figure it out. I started getting weird results and after hours of troubleshooting, I figured out that I had to sort the data before filtering it. Not sure why that matters but it did for me!

Thanks,

swjtx99
⚡ FREE TRIAL OFFER
Try out a week of full access for free.
Find out why thousands trust the EE community with their toughest problems.