Forum Discussion
Import Excel and Sort by eMail-Domain
PaddyB Connect to the CSV file with PowerQuery (PQ), do some transformations, sort and load back to Excel. Sound easy! And it is, though, you need to learn the basics of PQ first. The link below would be a good starting point.
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
- Yea_SoDec 28, 2021Bronze Contributor
I would go with what Mr Van_Eekelen suggested because you set up power query once and it will repeat the process just by pressing the update all button, so if you setup a query by folder all you have to do is drop the new file into a folder then open the pq workbook and press ctrl+alt+f5 and it will update the workbood with the new data.
- bosinanderDec 29, 2021Steel Contributor
Yea_So IMHO Power Query (PQ) is a nice alternative when connecting to slow changing data since it demands a specific update event in Excel.
PQ also needs a completly different set of skills compared to worksheets but it may pay back by providing a bunch of nice features like unpivot.
To get the transformed data, in this case email addresses sliced and separated by domain names to different sheets, PQ need to have a separate question for each domain. They can all be based on the same connection to the source file, but still need to be splitted into one separate 'question' for XXX.ch, another for XXX.de and a third for XXX.com since the wish is to have the result load to different sheets.With PQ alone it is needed to prepare a sheet for each domain and manually manage (append a new question and a new sheet) whenever a new domain appears.
I do not see any smooth way around that except using a macro to loop through the months domains and setup a sheet for each one found. And macros seem to not be an alternative for this user.
Loading the csv file via the menu Data and command From Text/CSV and then use a worksheet formula like NowshadAhmeds ought to be a pretty good solution as above Dec 26 2021 10:24.
- Yea_SoDec 29, 2021Bronze Contributor
yes it requires a one time query setup for each domain/sheet but after the initial query setup, the task becomes automatic just by pressing ctrl+alt+F5 to update all queries setup within the workbook so the cost benefit more than justifies the initial setup whereas with VBA the user might not be familiar with it and make maintaining more complicated as you have mentioned:
"To get the transformed data, in this case email addresses sliced and separated by domain names to different sheets, PQ need to have a separate question for each domain. They can all be based on the same connection to the source file, but still need to be splitted into one separate 'question' for XXX.ch, another for XXX.de and a third for XXX.com since the wish is to have the result load to different sheets.
With PQ alone it is needed to prepare a sheet for each domain and manually manage (append a new question and a new sheet) whenever a new domain appears."
if the user is not familiar with VBA how would the user maintain to update the code to add the VBA statements for the new domains?
- bosinanderDec 26, 2021Steel Contributor
> find a solution what more or less is working
Hi PaddyB
I have combined a few things into something attached that could be suitable for you.
Sheet Input;
Column A holds the email addresses and F2 visualizes the different email domains from A2 and down.
Sheet2 and 3 holds the email addresses from two different domains.
Similar to NowshadAhmed suggestion, each of those sheets shows the mail addresses related to the chosen domain.
The selection list shows domains not already used on another sheet.
Since xxx.com is selectable, there is no sheet for that domain. Copy Sheet2 (right click the tab of Sheet2: Move or copy: [x] Create a copy and (move to end)) and select xxx.com in A1.
Sheet PowerPage has in column A a list of the workbooks sheets. They are also linked to respective sheet.
If you'ld like to know more about how the automatic sheet list works, you may read about version 4 macros at https://exceloffthegrid.com/using-excel-4-macro-functions/.
Column B shows the content from cell A1 in each sheet using the function INDIRECT.
F2 lists the unique domains using
=LET( data; OFFSET(Input!A:A;1;0;COUNTA(Input!A:A)-1;1); output; UNIQUE(MID(data;FIND("@";data)+1;4711)); output )
H2 lists the domains that are missing an own sheet;
=FILTER(F2#;ISERROR(XMATCH(F2#;B:B)))
Finally, cell A1 at the different domain sheets have a data validation list that suggests any missing domain, listed in H2 with its spill area (H2#)
Instead using F2 would be like NowshadAhmed suggested.
-/-
The file attached contains version 4 macros and has to be saved as xlsM.
To activate them it seems nowadays necessary to include a VBA macro to get the enable question.
To get the sheet list updated, you may have to save, close and repoen the file (with macros enabled without question).
The VBA macro (that trigs the yellow enable question bar) is also a shortcut to activate the index sheet/first sheet.
Sub activateSheet1() ' ' Keyboard Shortcut: Ctrl+Shift+A ' ThisWorkbook.Activate Sheets(1).Select End Sub
Finally, try Data: From Text/CSV to connect to the csv file could be worth the while as a first step to using Power Query. You will get the csv data into a new sheet and you just have to cut that new table and paste it at cell input!A2 to have it all quite automatic with Ctrl+Alt+F5.
- Riny_van_EekelenDec 26, 2021Platinum 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.