Want to copy only fist and second row after applying autofilter in VBA if data is available after autofilter

Arif_Tamboli

New Member
Joined
Mar 1, 2018
Messages
34
Office Version
  1. 2016
I want to copy only first and second row after applying autofilter in VBA.
My code
row_no = ThisWorkbook.Sheets("Agent List").Range("B" & Application.Rows.Count).End(xlUp).Row
For I = 3 To row_no
AGENTNAME = ThisWorkbook.Sheets("Agent List").Cells(I, 2).Value
ThisWorkbook.Sheets("Main Data").Activate
ThisWorkbook.Sheets("Main Data").Range("A1:J1").AutoFilter Field:=7, Criteria1:=AGENTNAME
On Error Resume Next
below mentioned line code is copying all the visible rows
ActiveSheet.UsedRange.SpecialCells(xlCellTypeVisible).Areas(2).Copy
I don't want that
just want first and second visible row if data is available
 

Excel Facts

How can you turn a range sideways?
Copy the range. Select a blank cell. Right-click, Paste Special, then choose Transpose.
Your welcome. I do hope it helped, I am sure someone will jump in and let you know how to do it directly from the filter.

I personally will study the process more so I can give better advice in the future
 
Upvote 0

Forum statistics

Threads
1,216,496
Messages
6,130,982
Members
449,611
Latest member
Bushra

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