Deselect specific columns from filtered rows

Gaurangg

Board Regular
Joined
Aug 6, 2015
Messages
134
Dear Folks,

I am trying to select specific columns from the filtered data but it select the all the columns. Can anyone help with the changes in my code.

In my below code, it selects from A to P but I want to select A to N only. Please anyone can help where I can make changes into my code.


Code:
Sheets("MyWork").Select
    Rng2 = Sheets("MyWork").Range("O210").End(xlUp).Row
    Range("P4").Select
    Range("$A$4:$P" & Rng2).AutoFilter Field:=16, Criteria1:="0"
    
    Range("A4:P" & Rng2).Select
    ActiveCell.Offset(1, 0).Select
    Do Until ActiveCell.EntireRow.Hidden = False
        ActiveCell.Offset(1, 0).Select
    Loop
    Range(Selection, Selection.End(xlDown)).Select
    Range(Selection, Selection.End(xlToRight)).Select
    
    Selection.Copy
 
Last edited:

Excel Facts

Did you know Excel offers Filter by Selection?
Add the AutoFilter icon to the Quick Access Toolbar. Select a cell containing Apple, click AutoFilter, and you will get all rows with Apple
Code:
Sheets("MyWork").Select    
Rng2 = Sheets("MyWork").Range("N210").End(xlUp).Row
    Range("N4").Select
    Range("$A$4:$N" & Rng2).AutoFilter Field:=14, Criteria1:="0"
    
    Range("A4:N" & Rng2).Select
    ActiveCell.Offset(1, 0).Select
    Do Until ActiveCell.EntireRow.Hidden = False
        ActiveCell.Offset(1, 0).Select
    Loop
    Range(Selection, Selection.End(xlDown)).Select
    Range(Selection, Selection.End(xlToRight)).Select
    
    Selection.Copy
 
Last edited:
Upvote 0
Hi Mrshl,

Thanks for your reply. However I is not working. Coz the data points are available from column A to P and filteration criteria need to select from Column P however need to copy the data from column A to N only. I don't want to copy the column O and P as these columns contains some valid checks.
 
Upvote 0
Not entirely sure what you are trying to do, but if you simply want to copy the visible cells, try
Code:
    Dim Rng As Range
    
    Sheets("MyWork").Select
    rng2 = Range("O210").End(xlUp).Row
    Range("P4").Select
    Range("A4:P" & rng2).AutoFilter Field:=16, Criteria1:="0"
    On Error Resume Next
    Set Rng = Range("A5:N" & rng2).SpecialCells(xlVisible)
    On Error GoTo 0
    If Not Rng Is Nothing Then
        Rng.Copy
    Else
        MsgBox "Nothing to copy"
    End If
 
Upvote 0

Forum statistics

Threads
1,223,903
Messages
6,175,284
Members
452,630
Latest member
OdubiYouth

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