For Each WS in WB - Copy NonBlank Cells in Col 'E'

MikeL

Active Member
Joined
Mar 17, 2002
Messages
488
Office Version
  1. 365
Platform
  1. Windows
Hi,
Have a Workbook (WB) with multiple Worksheets (WS)

How does one copy the NONBLANK contents of Col E in each Worksheet and place into Col A of a New or Summary WS in the same WB?

Thanks in advance.
 

Excel Facts

Is there a shortcut key for strikethrough?
Ctrl+S is used for Save. Ctrl+5 is used for Strikethrough. Why Ctrl+5? When you use hashmarks to count |||| is 4, strike through to mean 5.
Hi Mikel
Try this, untested....don't have excel at my workstation at the moment
Code:
Sub copyem()
Dim lr As Long, ws As Worksheet, lrs As Long
Application.ScreenUpdating = False
For Each ws In Worksheets
    If ws.Name <> "Summary" Then
        ws.Activate
        lr = Cells(Rows.Count, "E").End(xlUp).Row
        lrs = Sheets("Summary").Cells(Rows.Count, "E").End(xlUp).Row
        With Range("E1:E" & lr)
            .AutoFilter
            .AutoFilter Field:=1, Criteria1:="<>"
            .SpecialCells(xlCellTypeVisible).Copy Destination:=Sheets("Summary").Range("E" & lrs + 1)
        End With
        lrs = Sheets("Summary").Cells(Rows.Count, "E").End(xlUp).Row
    End If
Next ws
Application.ScreenUpdating = True
End Sub
 
Upvote 0
oops, sorry, just noticed a typo
Code:
Sub copyem()
Dim lr As Long, ws As Worksheet, lrs As Long
Application.ScreenUpdating = False
For Each ws In Worksheets
    If ws.Name <> "Summary" Then
        ws.Activate
        lr = Cells(Rows.Count, "E").End(xlUp).Row
        lrs = Sheets("Summary").Cells(Rows.Count, "A").End(xlUp).Row
        With Range("E1:E" & lr)
            .AutoFilter
            .AutoFilter Field:=1, Criteria1:="<>"
            .SpecialCells(xlCellTypeVisible).Copy Destination:=Sheets("Summary").Range("A" & lrs + 1)
            .AutoFilter
        End With
    End If
Next ws
Application.ScreenUpdating = True
End Sub
 
Upvote 0
Thanks for the code.
I am getting a 1004 error -AutoFilter method of Range class failed

With Range("E1:E" & lr)
.AutoFilter
.AutoFilter Field:=1, Criteria1:="<>"
.SpecialCells(xlCellTypeVisible).Copy Destination:=Sheets("Summary").Range("A" & lrs + 1)
.AutoFilter
End With

Any reason that AutoFilter is in the code twice?

Thanks
 
Upvote 0
The Autofilter text is in twice....once to turn it on, and once to turn it off at the end.
Try running the code manually, by putting your cursor anywhere in the code and then pressing F8 for each step....the yellow highlighted line will tell us where the error is....hopefully.
Does the dat already have autofilter turned on ? if so turn it off for all sheets.
 
Upvote 0
I ran it thru the debug and made sure there were no filters in any of the WS.

It breaks at the .AutoFilter line with the 1004 error. I can google the error in the meantime.

Mike
 
Upvote 0
'bout the only thing that comes to mind is that there is a sheet with column "E" completely blank.
Would that be happening ?
 
Upvote 0
I have data in each WS, col E.
Unfortunate that is not the solution. I will keep searching about this.

Mike
 
Upvote 0
OK, column "E", hidden maybe ?
 
Upvote 0

Forum statistics

Threads
1,203,631
Messages
6,056,432
Members
444,864
Latest member
Thundama

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