Auto sort and email

sknight22

Board Regular
Joined
Feb 16, 2016
Messages
75
Hello

I have a large database of orders that need to be sent out to various email addresses and wondered; if one column contains company numbers, is it possible for a macro to filter the data into separate tabs (grouped by the company) and email out to specified addresses?

I’ve seen something similar but can’t find it

I hope you can help

Thanks

Sknight22
 

Excel Facts

Why are there 1,048,576 rows in Excel?
The Excel team increased the size of the grid in 2007. There are 2^20 rows and 2^14 columns for a total of 17 billion cells.
This will do the first, but not the e-mail.
Code:
Sub FilterCopy()
   Dim Cl As Range
   Dim Ws As Worksheet
   
   Set Ws = Sheets("[COLOR=#ff0000]Pcode[/COLOR]")
Application.ScreenUpdating = False
   If Ws.AutoFilterMode Then Ws.AutoFilterMode = False
   With CreateObject("scripting.dictionary")
      For Each Cl In Ws.Range("[COLOR=#ff0000]A2[/COLOR]", Ws.Range("[COLOR=#ff0000]A[/COLOR]" & Rows.Count).End(xlUp))
         If Not .exists(Cl.Value) Then
            Sheets.Add(, Sheets(Sheets.Count)).Name = Cl.Value
            .Add Cl.Value, Nothing
            Ws.Range("[COLOR=#ff0000]A1:U1[/COLOR]").AutoFilter 1, Cl.Value
            Ws.AutoFilter.Range.SpecialCells(xlVisible).Copy Sheets(Cl.Value).Range("A1")
         End If
      Next Cl
   End With
   Ws.AutoFilterMode = False
End Sub
Change the sheet name to suit.
Its based on your company names being in col A with a header in row 1 cols A:U. Change values in red to suit
 
Upvote 0
Hello,

Thank you for your response.

This works great but it flags an error with "Sheets.Add(, Sheets(Sheets.Count)).Name = Cl.Value" highlighted, but not sure why.

Also, if the company names were in Column H what would I need to change?

Thanks again for your help

Stephen
 
Upvote 0
To look in col H try
Code:
Sub FilterCopy()
   Dim Cl As Range
   Dim Ws As Worksheet
   
   Set Ws = Sheets("[COLOR=#ff0000]Pcode[/COLOR]")
Application.ScreenUpdating = False
   If Ws.AutoFilterMode Then Ws.AutoFilterMode = False
   With CreateObject("scripting.dictionary")
      For Each Cl In Ws.Range("[COLOR=#ff0000]H2[/COLOR]", Ws.Range("[COLOR=#ff0000]H[/COLOR]" & Rows.Count).End(xlUp))
         If Not .exists(Cl.Value) Then
            Sheets.Add(, Sheets(Sheets.Count)).Name = Cl.Value
            .Add Cl.Value, Nothing
            Ws.Range("A1:U1").AutoFilter [COLOR=#ff0000]8[/COLOR], Cl.Value
            Ws.AutoFilter.Range.SpecialCells(xlVisible).Copy Sheets(Cl.Value).Range("A1")
         End If
      Next Cl
   End With
   Ws.AutoFilterMode = False
End Sub
Are they Company names or numbers?
 
Last edited:
Upvote 0
Sorry they are company names. I’m not sure why I typed numbers in the original post.
Thanks I will try that
 
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,181
Members
453,022
Latest member
Mohamed Magdi Tawfiq Emam

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