Duplicate Declaration In Current Scope

CROY1985

Well-known Member
Joined
Sep 21, 2009
Messages
501
Office Version
  1. 365
Platform
  1. Windows
Hi Guys

I had some help yesterday in getting some code to rename a new sheet, regardless of which sheetnumber excel assigns it.

Now, when i have replicated the code - because i want to create more than 1 new sheet, i get the error "Duplicate declaration in current scope".

Code:
    Selection.AutoFilter
        
        ActiveSheet.ListObjects("Table_Query_from_Sage_Accounts_2011_1").Range. _
        AutoFilter Field:=1, Criteria1:="=*00", Operator:=xlOr, Criteria2:= _
        "=*all*"
    Cells.Select
    Selection.Copy
    Dim a As Worksheet
    Set a = Sheets.Add(After:=Sheets(Sheets.Count))
    a.Name = "Marshall Street"
    Selection.PasteSpecial Paste:=xlPasteAllUsingSourceTheme, Operation:=xlNone _
        , SkipBlanks:=False, Transpose:=False
    Columns("A:A").Select
    Selection.EntireColumn.Hidden = True
      Columns("B:B").Select
    Sheets("Sheet1").Select
    Range("b4").Select
    
        ActiveSheet.ListObjects("Table_Query_from_Sage_Accounts_2011_1").Range. _
        AutoFilter Field:=1, Criteria1:="=*01", Operator:=xlOr, Criteria2:= _
        "=*all*"
    Cells.Select
    Selection.Copy
    Dim a As Worksheet
    Set a = Sheets.Add(After:=Sheets(Sheets.Count))
    a.Name = "Roundhay Road"
    Selection.PasteSpecial Paste:=xlPasteAllUsingSourceTheme, Operation:=xlNone _
        , SkipBlanks:=False, Transpose:=False
    Columns("A:A").Select
    Selection.EntireColumn.Hidden = True
      Columns("B:B").Select
    Sheets("Sheet1").Select
    Range("b4").Select
    Selection.AutoFilter
        
        For Each ws In Sheets
    If ws.Name <> "sheet 1" Then
        LR = ws.UsedRange.Rows(ws.UsedRange.Rows.Count).Row
        For i = LR To 2 Step -1
            If ws.Cells(i, 7).EntireRow.Hidden = True Then ws.Cells(i, 7).EntireRow.Delete
        Next i
    End If
    Next ws

As you can see, what im trying to do is create a seperate sheet for the data on sheet1 after a filter has been applied. And then afterwards it goes through and deletes all hidden rows.

I ultimately have about 25 filters to apply to the data and require a new sheet for each one. But i think if we can get the code right for the first couple, then i should be able to manage on my own.

Thanks
 

Excel Facts

How to change case of text in Excel?
Use =UPPER() for upper case, =LOWER() for lower case, and =PROPER() for proper case. PROPER won't capitalize second c in Mccartney

Forum statistics

Threads
1,224,599
Messages
6,179,831
Members
452,946
Latest member
JoseDavid

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