Help with find and delete please

EagerToLearn

New Member
Joined
Jan 20, 2011
Messages
20
Hello there,
I have a simple question
I have a work book contains our sales for 5 years
Every sheet in this work book contains sales for one month.
Sales is by costumer in each sheet.
How can I create a simple macro that finds sales for a specific customer in every sheet, after finding the sales for that customer, either delete all other customers and leave that customer on the sheet, or make a copy of that sales and copy it to another file
The purpose of this macro is to get the sales for that customer for every month for the last 5 years.
I do not have a problem of having a macro works for one sheet and I can run it again for every single other sheet.
Your help is much appreciated.:eeek:
 

Excel Facts

Workdays for a market open Mon, Wed, Friday?
Yes! Use "0101011" for the weekend argument in NETWORKDAYS.INTL or WORKDAY.INTL. The 7 digits start on Monday. 1 means it is a weekend.
Hello there,
I have a simple question
I have a work book contains our sales for 5 years
Every sheet in this work book contains sales for one month.
Sales is by costumer in each sheet.
How can I create a simple macro that finds sales for a specific customer in every sheet, after finding the sales for that customer, either delete all other customers and leave that customer on the sheet, or make a copy of that sales and copy it to another file
The purpose of this macro is to get the sales for that customer for every month for the last 5 years.
I do not have a problem of having a macro works for one sheet and I can run it again for every single other sheet.
Your help is much appreciated.:eeek:

Untested, and not sure if something like this is what you're looking for, but maybe it'll give you some ideas.

Code:
Sub EagerToLearn()
Dim ws As Worksheet
Dim lr As Long

x = InputBox("Please Enter Customer Name to Search")

Sheets.Add.Name = x

For Each ws In ThisWorkbook.Sheets

    If ws.Name <> x Then
    
    lr = Cells(Rows.Count, 1).End(xlUp).Row
    
        With Range(Range("A2"), Range("A" & lr))
        
            .AutoFilter Field:=1, Criteria1:=x
            .SpecialCells(xlCellTypeVisible).EntireRow.Copy Sheets(x).Range("A" & Rows.Count).End(xlUp)(2)
            .AutoFilter
            
        End With
        
    End If
    
Next
        
End Sub
 
Upvote 0
Hello,
Thank you very much for your help, I will go ahead and try it.
really appreciate the time you spent on that.:eeek:
 
Upvote 0
Hello
I tried it.
I was using step by step (F8) to see where it is giving the error message number 400.
It creates the x sheet and goes through the if statement but returns no data, then the second time it goes through the if statement and gets stuck in this line
.SpecialCells(xlCellTypeVisible).EntireRow.Copy Sheets(x).Range("A" & Rows.Count).End(xlUp)(2).
Is there any way I can sent you a test file with some date in it?
Thanks
:eeek:
 
Upvote 0
Hello
I tried it.
I was using step by step (F8) to see where it is giving the error message number 400.
It creates the x sheet and goes through the if statement but returns no data, then the second time it goes through the if statement and gets stuck in this line
.SpecialCells(xlCellTypeVisible).EntireRow.Copy Sheets(x).Range("A" & Rows.Count).End(xlUp)(2).
Is there any way I can sent you a test file with some date in it?
Thanks
:eeek:

See my PM.
 
Upvote 0
Hello
I tried it.
I was using step by step (F8) to see where it is giving the error message number 400.
It creates the x sheet and goes through the if statement but returns no data, then the second time it goes through the if statement and gets stuck in this line
.SpecialCells(xlCellTypeVisible).EntireRow.Copy Sheets(x).Range("A" & Rows.Count).End(xlUp)(2).
Is there any way I can sent you a test file with some date in it?
Thanks
:eeek:

Maybe with these changes:

Code:
Sub EagerToLearn()
Dim ws As Worksheet
Dim lr As Long

x = InputBox("Please Enter Customer Name to Search")

Sheets.Add.Name = x

For Each ws In ThisWorkbook.Sheets

    If ws.Name <> "x" Then
    
    lr = Cells(Rows.Count, 1).End(xlUp).Row
    
        With Range(Range("A2"), Range("A" & lr))
        
            .AutoFilter Field:=1, Criteria1:=x
            .SpecialCells(xlCellTypeVisible).EntireRow.Copy Sheets(x).Range("A" & Rows.Count).End(xlUp)(2)
            .AutoFilter
            
        End With
        
    End If
    
Next
        
End Sub
 
Upvote 0

Forum statistics

Threads
1,224,566
Messages
6,179,551
Members
452,927
Latest member
rows and columns

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