Forum Discussion

PaddyB's avatar
PaddyB
Brass Contributor
Dec 25, 2021

Import Excel and Sort by eMail-Domain

Hi all

 

merry XMAS to you all

 

I use the time to get some "long term wish" fixed but no luck at all - excel is not my "world" 🙂

 

my problem ist

I get every month a CSV from one of our "SaaS Services" - I nee now to import this to a Blank (or Template if it would help) and do the following

 

- take all eMail Addresses with ending @XXX.ch and put this to the Tab XXX.ch

- take all eMail Addresses with ending @XXX.de and put this to the Tab XXX.de

- take all eMail Addresses with ending @XXX.com and put this to the Tab XXX.com

 

These are just 3 examples, I have to do this for a lot of domains - every month

 

again, I have no idea to use Excel for more than my Expense report 🙂 

can someone help me here?

 

    • PaddyB's avatar
      PaddyB
      Brass Contributor
      Hi Riny

      for sure a working idea - but just to learn something completely new take many hours/days for a task that I need to do once a month 🙂

      so if I do not find a solution what more or less is working, I will do it by hand - will be quicker
      • Riny_van_Eekelen's avatar
        Riny_van_Eekelen
        Platinum Contributor

        PaddyB Your choice. But I'd recommend to look into PQ anyway. Guaranteed that you'll find other uses for it that will save you huge amounts of time in other jobs you might be doing.

  • NowshadAhmed's avatar
    NowshadAhmed
    Iron Contributor

    You might need to use a macro to create the worksheet based on unique domain names. And then another macro to copy the relevant data for the domain names. You might need to separate the domain name from the email addresses first. Something like this will help:
    RIGHT(A1,LEN(A1)-FIND("@",A1,1))
    Once you separate the names, macro can do the rest.

    Side note: If I were to do the work, I would not create separate sheets for each domain. I would lump them in one formatted table and filter them to display only those I need to work on.

    • PaddyB's avatar
      PaddyB
      Brass Contributor
      I will give this a try - but not the Macro 🙂
  • bosinander's avatar
    bosinander
    Steel Contributor

    I interpret 'lot of domains' as between 4 and 100 and assume that quite a few of them are new from month to month.
    As described 26 Dec 2021 10:24 AM above, the attached file calculates the domains in the input addresses. Column A may be pasted or loaded via Data: (Get & Transform): From Text/CSV.

    __/ Sheet3 has one of the domains entered into A1 and uses FILTER to fetch the addresses in that domain.

    A3:

    =FILTER(Input!A:A;IFERROR(FIND("@"& A1;Input!A:A);0))

    __/ The first sheets;

    • Column A shows the sheets in the workbook
    • Column B shows the value in each sheets cell A1 (as chosen in C2)
    • Column H shows the domains that not yet have its own sheet
      It is calculated by comparing column B with hidden column F (press Ctrl+8 to show its [+])

    Click the button to generate the missing sheets.

    __/ The macro will generate sheets for each missing domain as follows:

    Sub domains2sheets()
        While Not IsError(Range("domains_without_sheet").Value)
            Sheets(Sheets.Count).Select
            If Not Range("a1").Value Like "?*.?*" Then
                MsgBox "Last sheet seems to not be a valid template?"
                Exit Sub
            Else
                Sheets(Sheets.Count).Copy After:=Sheets(Sheets.Count)
                Sheets(Sheets.Count).Name = "Sheet" & Sheets.Count
                Range("a1").Value = Range("domains_without_sheet").Value
            End If
        Wend
        Sheets(1).Select
    End Sub

    The defined name domains_without_sheet refers to =PowerPage!$H$2

    Row 9 could just as well be 

    Sheets(Sheets.Count).Name = Range("domains_without_sheet").Value

    but would be misleading if cell A1 is changed.

     

    Since it's just once a month, I think a paste and a click could be automatic enough.

    It is also possible to select sheet4 and Shift+click the last sheet and delete them to only have the current months domains.

    For this purpose or rather to get an overview of the number of items in each domain, I also added a counter in PowerPage!D:D. Minus one to exclude the sheets title.

     

    • Yea_So's avatar
      Yea_So
      Bronze Contributor

      bosinander 

       

      You might want to look into merge query "merge" using the join type anti-left or anti-right depending on which list is selected in the dialog box to isolate and create a new domains list where the current csv list does not match the current master list.

       

      if the new csv get and transform list is selected as the first list, use join type anti-right to get the new domains list

       

      if the new csv get and transform list is selected as the second list use anti-left to get the new domains list

       

      after getting the new domains list, use the query merge "append" to add the new domains list into the master list

      • bosinander's avatar
        bosinander
        Steel Contributor
        Yes, but let's assume that you get 60 domains whereof 40 are new and 35 not around this month. As long as the demand is to have the addresses gathered by domain on separate sheets, there will be a lot of manual work to load each new domain question to a separate new sheet and probably delete domain sheets not in use.
        I think the separation would be best done using more or less familiar worksheet functions and eventually combine them with oa few lines of code as mentioned above.
        However I like the for me new approach to consider merge (aka join) anti-left and anti-right. That may become handy when describing the functionality in yet another way 🙂

Resources