Ignore one sheet and run

Chandresh

Board Regular
Joined
Jul 21, 2009
Messages
146
HI All,

I am using below code to run a macro however facing some issue , could you please help.

what macro does- filters data in all sheets based on certain criteria and copy the filtered data to Summarynew sheet.( below macro should ignore "Summary sheet" and run on all other sheets )other sheet

Code:
Sub RunFornew()
Dim xWs As Worksheet
On Error Resume Next
For Each xWs In Worksheets
' for filter
Columns("A:W").Select
    'Selection.AutoFilter
    xWs.Range("$A$2:$W$500000").AutoFilter Field:=22, Criteria1:= _
        "=Notional", Operator:=xlAnd
Next
    
    ' for copying data in summary new
    Dim sh As Worksheet
    Dim DestSh As Worksheet
    Dim lRow As Long
    Dim CopyRng As Range
    With Application
        .ScreenUpdating = False
        .EnableEvents = False
    End With
On Error GoTo Ouch
' Delete the summary sheet if it exists.
    Application.DisplayAlerts = False
       On Error Resume Next
       ActiveWorkbook.Worksheets("SummaryNew").Delete
        On Error GoTo 0
    Application.DisplayAlerts = True
' Add a new summary worksheet.
    Set DestSh = ActiveWorkbook.Worksheets.Add
        DestSh.Name = "Summarynew"

For Each sh In ActiveWorkbook.Worksheets
        If sh.Name <> DestSh.Name Then
   
        With sh
            'edited
            
            Set CopyRng = .Range("A2:W" & .Cells(Rows.Count, 1).End(xlUp).Row)
        End With
    
        lRow = DestSh.Cells(Rows.Count, 1).End(xlUp).Row
        
        If lRow = 1 Then
            CopyRng.SpecialCells(xlCellTypeVisible).Copy DestSh.Range("A" & lRow)
            With DestSh
                Set CopyRng = .Range("X1:X" & .Cells(Rows.Count, 1).End(xlUp).Row)
                    'CopyRng.Value = sh.Name
                    CopyRng.Value = "New"
            End With
        Else
            CopyRng.SpecialCells(xlCellTypeVisible).Copy DestSh.Range("A" & lRow + 1)
            With DestSh
                Set CopyRng = .Range("X" & lRow + 1 & ":X" & .Cells(Rows.Count, 1).End(xlUp).Row)
                    CopyRng.Value = "New"
            End With
        End If
    End If
Next sh
Ouch:
    With Application
        .ScreenUpdating = True
        .EnableEvents = True
    End With


End Sub
 
Last edited by a moderator:

Excel Facts

Can you AutoAverage in Excel?
There is a drop-down next to the AutoSum symbol. Open the drop-down to choose AVERAGE, COUNT, MAX, or MIN
you need an if statement

Code:
For Each xWs In Worksheets
if xws.name <> "Summary sheet" then
'your code
end if
next xws
 
Upvote 0
HI Thanks for your reply , however I am still facing the issue, could you please send me the entire code.

Thanks in advance
 
Upvote 0
When you say
Code:
below macro should ignore "Summary sheet" and run on all other sheets
do you mean the newly created sheet called "Summarynew"?
If so your code should already be doing that.
If it's not please explain what is happening.
 
Upvote 0
When you say
Code:
below macro should ignore "Summary sheet" and run on all other sheets
do you mean the newly created sheet called "Summarynew"?
If so your code should already be doing that.
If it's not please explain what is happening.

Hi I have many worksheets in the workbook in that there are 2 different worksheet with name 1) summary
2) summarynew

Above macro should copy the filtered data from all the worksheets (except summary worksheet ) and paste in summarynew worksheet

Thanks
 
Upvote 0
In that case try
Code:
 If Sh.Name <> DestSh.Name And Sh.Name <> "Summary" Then
 
Upvote 0

Forum statistics

Threads
1,223,904
Messages
6,175,295
Members
452,631
Latest member
a_potato

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