Filter Data and Email then Refilter Data and Email.

dataislife

New Member
Joined
Oct 12, 2015
Messages
2
Hello,

This is my first post. I am managing a group of 20 salesmen. I want to send each salesmen a report every week but I don't want to do it manually.

Is there an easier way to do this?

I am thinking VBA and advanced filter.

How do i post my spreadsheet?

Thanks,
 

Excel Facts

Formula for Yesterday
Name Manager, New Name. Yesterday =TODAY()-1. OK. Then, use =YESTERDAY in any cell. Tomorrow could be =TODAY()+1.
Every salesmen is linked to a number (1-20). I change Cell C1 to get a different salesmen. I am using vlookup and advanced filter.


Sub Mail_every_Worksheet()
Dim sh As Worksheet
Application.ScreenUpdating = False
Range("C1").Select
ActiveCell.FormulaR1C1 = "1"
Range("A4").Select
Range("A4:H9").AdvancedFilter Action:=xlFilterInPlace, CriteriaRange:=Range _
("B1:B2"), Unique:=False
For Each sh In ThisWorkbook.Worksheets
If sh.Range("a1").Value Like "*@*" Then
sh.Copy
ActiveWorkbook.SaveAs "Sheet " & sh.Name & " of " _
& ThisWorkbook.Name & ".xls"
ActiveWorkbook.SendMail ActiveSheet.Range("a1").Value, _
"Subject_line"
ActiveWorkbook.ChangeFileAccess xlReadOnly
Kill ActiveWorkbook.FullName
ActiveWorkbook.Close False
End If
Next sh
Application.ScreenUpdating = True
Range("C1").Select
ActiveCell.FormulaR1C1 = "2"
Range("A4").Select
Range("A4:H9").AdvancedFilter Action:=xlFilterInPlace, CriteriaRange:=Range _
("B1:B2"), Unique:=False
For Each sh In ThisWorkbook.Worksheets
If sh.Range("a1").Value Like "*@*" Then
sh.Copy
ActiveWorkbook.SaveAs "Sheet " & sh.Name & " of " _
& ThisWorkbook.Name & ".xls"
ActiveWorkbook.SendMail ActiveSheet.Range("a1").Value, _
"Subject_line"
ActiveWorkbook.ChangeFileAccess xlReadOnly
Kill ActiveWorkbook.FullName
ActiveWorkbook.Close False
End If
Next sh
Application.ScreenUpdating = True
End Sub


I am getting a run-time error "1004"
The file name or path does not exist.
the file is being used by another program.
the workbook you are trying to save has the same name as the currently open workbook.
 
Last edited:
Upvote 0

Forum statistics

Threads
1,214,645
Messages
6,120,711
Members
448,984
Latest member
foxpro

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