Tweak Macro to Ignore or Remove Filtering

welshraz

New Member
Joined
Apr 29, 2016
Messages
39
Office Version
  1. 365
Platform
  1. Windows
Morning!

Hope someone can help me tweak this macro a little. It works for what I need, i.e. combining the data from 10 or so worksheets into a master tab, and ignoring a selection of others. What I need it to also do is ignore any filtering on the tabs it compiles, or remove the filtering before copying.

VBA Code:
Sub combinedata()
Dim var As Integer
Dim Sh As Worksheet
var = 0
For Each Sh In Worksheets
If Sh.Name = "Master" Then
var = 1
Exit For
End If
Next Sh
For Each Sh In Worksheets
If Sh.Name <> ActiveSheet.Name And Sh.Name <> "Landing Page" And Sh.Name <> "Build Completes" Then
With Sh
.Range("A3:AC" & .Range("A" & Rows.Count).End(xlUp).Row).Copy _
Range("A" & Range("A" & Rows.Count).End(xlUp).Row + 1)
End With
End If
Next Sh
ActiveWindow.DisplayGridlines = False
Range("A3").CurrentRegion.Select
End Sub

Any help or guidance greatly received.
 

Excel Facts

Copy a format multiple times
Select a formatted range. Double-click the Format Painter (left side of Home tab). You can paste formatting multiple times. Esc to stop
Morning!

Hope someone can help me tweak this macro a little. It works for what I need, i.e. combining the data from 10 or so worksheets into a master tab, and ignoring a selection of others. What I need it to also do is ignore any filtering on the tabs it compiles, or remove the filtering before copying.

VBA Code:
Sub combinedata()
Dim var As Integer
Dim Sh As Worksheet
var = 0
For Each Sh In Worksheets
If Sh.Name = "Master" Then
var = 1
Exit For
End If
Next Sh
For Each Sh In Worksheets
If Sh.Name <> ActiveSheet.Name And Sh.Name <> "Landing Page" And Sh.Name <> "Build Completes" Then
With Sh
.Range("A3:AC" & .Range("A" & Rows.Count).End(xlUp).Row).Copy _
Range("A" & Range("A" & Rows.Count).End(xlUp).Row + 1)
End With
End If
Next Sh
ActiveWindow.DisplayGridlines = False
Range("A3").CurrentRegion.Select
End Sub

Any help or guidance greatly received.

Try below

VBA Code:
Sub combinedata()
Dim var As Integer
Dim Sh As Worksheet
var = 0
For Each Sh In Worksheets
If Sh.Name = "Master" Then
var = 1
Exit For
End If
Next Sh
For Each Sh In Worksheets
If Sh.Name <> ActiveSheet.Name And Sh.Name <> "Landing Page" And Sh.Name <> "Build Completes" Then
With Sh
Selection.AutoFilter
.Range("A3:AC" & .Range("A" & Rows.Count).End(xlUp).Row).Copy _
Range("A" & Range("A" & Rows.Count).End(xlUp).Row + 1)
End With
End If
Next Sh
Selection.AutoFilter
ActiveWindow.DisplayGridlines = False
Range("A3").CurrentRegion.Select
End Sub
 
Upvote 0
If the above does not work try to insert below line where you want the filter to remove.

Selection.AutoFilter
 
Upvote 0
T
Try below

VBA Code:
Sub combinedata()
Dim var As Integer
Dim Sh As Worksheet
var = 0
For Each Sh In Worksheets
If Sh.Name = "Master" Then
var = 1
Exit For
End If
Next Sh
For Each Sh In Worksheets
If Sh.Name <> ActiveSheet.Name And Sh.Name <> "Landing Page" And Sh.Name <> "Build Completes" Then
With Sh
Selection.AutoFilter
.Range("A3:AC" & .Range("A" & Rows.Count).End(xlUp).Row).Copy _
Range("A" & Range("A" & Rows.Count).End(xlUp).Row + 1)
End With
End If
Next Sh
Selection.AutoFilter
ActiveWindow.DisplayGridlines = False
Range("A3").CurrentRegion.Select
End Sub
Thanks for this, but I have run it an it is still ignoring any of the filtered rows and not adding them to the master tab.
 
Upvote 0
ok got it

Insert below and tweak filter part as per your requirement . This macro will copy all visible filtered cells.

VBA Code:
Dim Rng As Range
    Dim Rng_Del As Range

    'Apply autofilter to data range
    'Note: data must start in cell A1 for this macro to work
  
    Set Rng = Range("A1").CurrentRegion
    Rng.AutoFilter Field:=19, Criteria1:="FALSE", Operator:=xlOr, Criteria2:="=TRUE"
  
    'Copy visible rows assuming there's nothing else below the last row
  
    Rng.Offset(0, 0).SpecialCells(xlCellTypeVisible).Select
    Selection.Copy
 
Upvote 0
How about
VBA Code:
Sub combinedata()
Dim var As Integer
Dim Sh As Worksheet
var = 0
For Each Sh In Worksheets
If Sh.Name = "Master" Then
var = 1
Exit For
End If
Next Sh
For Each Sh In Worksheets
If Sh.Name <> ActiveSheet.Name And Sh.Name <> "Landing Page" And Sh.Name <> "Build Completes" Then
With Sh
.AutoFilterMode = False
.Range("A3:AC" & .Range("A" & Rows.Count).End(xlUp).Row).Copy _
Range("A" & Range("A" & Rows.Count).End(xlUp).Row + 1)
End With
End If
Next Sh
ActiveWindow.DisplayGridlines = False
Range("A3").CurrentRegion.Select
End Sub
 
Upvote 0

Forum statistics

Threads
1,214,583
Messages
6,120,380
Members
448,955
Latest member
BatCoder

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