Filtered data copying from one workbook to another

Manoj Gaidhankar

New Member
Joined
May 27, 2022
Messages
20
Office Version
  1. 2021
Platform
  1. Windows
Hi there,

Please find the below code

Scenario1

I'm trying apply a filter on column C using Autofilter and then using the SpecialCells to copy only the visible cells which belongs to the column C. Further, pasting it in another workbook.

Scenario 1.png


VBA Code:
  Workbooks("Book3.xlsx").Worksheets(1).Range("A1").AutoFilter

  Workbooks("Book3.xlsx").Worksheets(1). _
  Range("A1").AutoFilter Field:=3, Criteria1:="<>", Operator:=xlAnd, Criteria2:="<>-"

With Workbooks("Book3.xlsx").Worksheets(1)
    .Range("C2", .Range("C" & Rows.Count).End(3)). _
    SpecialCells(xlCellTypeVisible).Copy   '[B]Here the code copies the complete range and not the cell "C2" which is incorrect[/B]
   End With

  ActiveSheet. _
  Range("H" & Rows.Count).End(3)(2).PasteSpecial Paste:=xlPasteValues
  Application.CutCopyMode = False

Scenario2

I'm trying apply a filter on column D using Autofilter and then using the SpecialCells to copy only the visible cells which belongs to the column D. Further, pasting it in another workbook.

Scenario 2.png


VBA Code:
Workbooks("Book3.xlsx").Worksheets(2).Range("A1").AutoFilter

  Workbooks("Book3.xlsx").Worksheets(2). _
  Range("A1").AutoFilter Field:=4, Criteria1:="<>", Operator:=xlAnd, Criteria2:="<>-"

With Workbooks("Book3.xlsx").Worksheets(2)
    .Range("D2", .Range("D" & Rows.Count).End(3)). _
    SpecialCells(xlCellTypeVisible).Copy     '[B]Here the code copies the only cell "D3" correctly[/B]
    End With

  ActiveSheet. _
  Range("H" & Rows.Count).End(3)(2).PasteSpecial Paste:=xlPasteValues
  Application.CutCopyMode = False

Below is the table for your reference at the end.

Name1Name2Name3Name4
--Nick Martin-
NickNick-Nick
-Nick--
Nick MartinNick-
Nick MartinNick Martin-

Request you to please help me with this.

Thank you.
 

Excel Facts

Control Word Wrap
Press Alt+Enter to move to a new row in a cell. Lets you control where the words wrap.
I have already raised a concern on the below portal but there wasn't any update so raising a request here
 
Upvote 0

Forum statistics

Threads
1,214,651
Messages
6,120,744
Members
448,989
Latest member
mariah3

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