VBA-Help Filter data and then copy to destiantion sheet

Isabella

Well-known Member
Joined
Nov 7, 2008
Messages
643
Hi, i am after a code that will

1. Clear (formats) in the destination sheet then

2. Apply filter in sheet Source Row 5 and filter for "Y" then

3. Copy filter data to Sheet Dest

So from this

Excel Workbook
ABCDE
5BankAmountTrue AdjY/NComments
6CITI2.14Y
7JP0.01Y
8RBS12.36Y
9BONY0.08N
10NCS0.02Y
11STATE20.36Y
12CITI0.39Y
13
14
Source


To this

Excel Workbook
ABCD
5BankAmountTrue AdjY/N
6CITI2.14Y
7JP0.01Y
8RBS12.36Y
9NCS0.02Y
10STATE20.36Y
11CITI0.39Y
12
Dest
 

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)
Code:
Sub Test1()
Application.ScreenUpdating = False
With Worksheets("Dest")
Dim rng As Range
Set rng = Range("D6:D" & Cells(Rows.Count, 4).End(xlUp).Row)
.Cells.ClearFormats
Rows(5).Copy .Rows(5)
rng.Replace What:="N", Replacement:="", LookAt:=xlWhole, MatchCase:=False
On Error Resume Next
rng.SpecialCells(4).EntireRow.Hidden = True
rng.SpecialCells(12).EntireRow.Copy .Range("A6")
Err.Clear
Cells.EntireRow.Hidden = False
rng.Replace What:="", Replacement:="N"
End With
Set rng = Nothing
Application.ScreenUpdating = True
End Sub
 
Last edited:
Upvote 0
I cant see in the code Sheet Source? How is the macro copying the data to Sheet Dest?

Code:
Sub Test1()
Application.ScreenUpdating = False
With Worksheets("Dest")
Dim rng As Range
Set rng = Range("D6:D" & Cells(Rows.Count, 4).End(xlUp).Row)
.Cells.ClearFormats
Rows(5).Copy .Rows(5)
rng.Replace What:="N", Replacement:="", LookAt:=xlWhole, MatchCase:=False
On Error Resume Next
rng.SpecialCells(4).EntireRow.Hidden = True
rng.SpecialCells(12).EntireRow.Copy .Range("A6")
Err.Clear
Cells.EntireRow.Hidden = False
rng.Replace What:="", Replacement:="N"
End With
Set rng = Nothing
Application.ScreenUpdating = True
End Sub
 
Upvote 0
I assumed you had the Source sheet active at the time of macro execution.

This will cover you as long as the workbook is the active workbook, and assuming your source sheet is named Source, and your destination sheet is named Dest, as you depicted in your first post.


Code:
Sub Test2()
Application.ScreenUpdating = False
Dim rng As Range, srcSheet As Worksheet
Set srcSheet = Sheets("Source")
With Worksheets("Dest")
Set rng = srcSheet.Range("D6:D" & srcSheet.Cells(Rows.Count, 4).End(xlUp).Row)
.Cells.ClearFormats
srcSheet.Rows(5).Copy .Rows(5)
rng.Replace What:="N", Replacement:="", LookAt:=xlWhole, MatchCase:=False
On Error Resume Next
rng.SpecialCells(4).EntireRow.Hidden = True
rng.SpecialCells(12).EntireRow.Copy .Range("A6")
Err.Clear
srcSheet.Cells.EntireRow.Hidden = False
rng.Replace What:="", Replacement:="N"
End With
Set rng = Nothing: Set srcSheet = Nothing
Application.ScreenUpdating = True
End Sub
 
Upvote 0

Forum statistics

Threads
1,224,591
Messages
6,179,771
Members
452,941
Latest member
Greayliams

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