Copying filtered cells

harvey121

New Member
Joined
Nov 27, 2018
Messages
20
Hi All, I'm using the following code to filter the cells and then copy the filtered values. The code seems to be working for Sti but when I use it for Mon, the whole sheet data copies. Kindly help me identify what I'm doing wrong over here

This is what my data looks like:

[TABLE="width: 355"]
<tbody>[TR]
[TD]order_no
[/TD]
[TD]merchant_name[/TD]
[/TR]
[TR]
[TD="align: right"]101[/TD]
[TD]Mon[/TD]
[/TR]
[TR]
[TD="align: right"]102[/TD]
[TD]Sti[/TD]
[/TR]
</tbody>[/TABLE]

Code:
Sub Macro1()
Range("A1").Select
    Selection.AutoFilter
    ActiveSheet.Range("$A$1:$B$1000").AutoFilter Field:=2, Criteria1:= _
        "Mon*"


Dim LR As Long
    LR = Range("A" & Rows.Count).End(xlUp).Row
    Range("A2:A" & LR).SpecialCells(xlCellTypeVisible).Select
    
    Selection.Copy
End Sub
 

Excel Facts

Whats the difference between CONCAT and CONCATENATE?
The newer CONCAT function can reference a range of cells. =CONCATENATE(A1,A2,A3,A4,A5) becomes =CONCAT(A1:A5)
Maybe this

Code:
Sub MM1()
Dim LR As Long
LR = Range("A" & Rows.Count).End(xlUp).Row
With Range("A1")
    .AutoFilter
    .Range("$A$1:$B$" & LR).AutoFilter Field:=2, Criteria1:="Mon"
    .SpecialCells(xlCellTypeVisible).Copy
End With
End Sub
 
Upvote 0
Hi,
This also copies the whole data. I just need to copy column A values without it's header.

Maybe this

Code:
Sub MM1()
Dim LR As Long
LR = Range("A" & Rows.Count).End(xlUp).Row
With Range("A1")
    .AutoFilter
    .Range("$A$1:$B$" & LR).AutoFilter Field:=2, Criteria1:="Mon"
    .SpecialCells(xlCellTypeVisible).Copy
End With
End Sub
 
Upvote 0
Maybe this then
Code:
Sub MM1()
Dim LR As Long
LR = Range("A" & Rows.Count).End(xlUp).Row
With Range("A1")
    .AutoFilter
    .Range("$A$1:$B$" & LR).AutoFilter Field:=2, Criteria1:="Mon"
End With
Range("A2:A" & LR).SpecialCells(xlCellTypeVisible).Copy
End Sub
 
Upvote 0

Forum statistics

Threads
1,224,825
Messages
6,181,190
Members
453,020
Latest member
Mohamed Magdi Tawfiq Emam

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