Forum Discussion
Extracting date
I have a worksheet that includes client account information such as Client Name, Client Address, Account Number, Account Balance, Date Opened, Date Closed, etc. This information is collected in columns.
John Doe Jane Smith
123 Main St 321 Elm St
A/C# 001-0001 A/C#001-0002
$1000 $2000
Jan 1, 2020 Feb 1, 2020
June 20, 2020 Open
Putting all the information in columns is handy for creating pivot tables. But, I would also like to create an individual worksheet for each account so that I can keep the information in separate account files. I would like to automate the creation of this individual sheet.
Does excel have functions that allow for this?
Thank you.
13 Replies
- Subodh_Tiwari_sktneerSilver Contributor
If you are open to a VBA solution, you may try something like this...
Sub SplitDataToSheets() Dim wsData As Worksheet Dim dws As Worksheet Dim shName As String Dim lr As Long Dim lc As Long Dim Rng As Range Dim str As Variant Dim acRng As Range Dim dtRng As Range Application.ScreenUpdating = False Set wsData = Worksheets("Master") lr = wsData.Cells(Rows.Count, 1).End(xlUp).Row lc = wsData.Cells(2, Columns.Count).End(xlToLeft).Column For Each Rng In wsData.Rows(2).SpecialCells(xlCellTypeConstants, 2).Areas str = Split(Rng.Value, Chr(10)) shName = str(0) & " Account" Set acRng = wsData.Range(wsData.Cells(Rng.Row + 1, 1), wsData.Cells(lr, 1)) Set dtRng = wsData.Range(wsData.Cells(Rng.Row + 1, Rng.Column), wsData.Cells(lr, Rng.Column + 1)) On Error Resume Next Set dws = Worksheets(shName) dws.Cells.Clear On Error GoTo 0 If dws Is Nothing Then Set dws = Worksheets.Add(after:=Worksheets(Worksheets.Count)) dws.Name = shName End If dws.Range("B2").Value = Rng.Value acRng.Copy dws.Range("B3") dtRng.Copy dws.Range("C3") dws.Range("A3").Value = "#" dws.UsedRange.RowHeight = 15 With dws.Range("A4:A" & lr) .Formula = "=Row()-3" .Value = .Value End With With dws.Range("B2:D2") .Merge .Font.Bold = True .HorizontalAlignment = xlCenter .VerticalAlignment = xlCenter .RowHeight = 50 End With dws.UsedRange.Columns.AutoFit Set dws = Nothing Next Rng wsData.Select Application.ScreenUpdating = True End SubIn the attached, click the button called "Split Accounts" on Master Sheet.
- dlucas980Copper ContributorThank you. I have never used VBA. But, I am willing to try. If nothing else, I will learn something about VBA.
Thank you.
- mathetesGold Contributor
First off, storing data records in rows is the far more common way, and entirely suited to Pivot Tables. And then you can convert the range of data to an Excel Table and far more easily do other things as well--e.g., take advantage of the newer Dynamic Array functions SORT, UNIQUE, FILTER...
So let me first disabuse you of the notion that having your client account information in columns is suitable. They may work for Pivot Tables, because of the flexibility of Pivot Tables, but they'll end up limiting you more than helping you. Seriously. Check out any texts on data bases and tables in Excel; I doubt you'll find a one that advocates doing the records as columns.
Second, could you say more about what you'll be storing in those individual sheets, one per client, and maybe a word or two about how many clients you're talking about.
It's clearly a database of some kind that you're building. The question is what would be the best database design to accomplish your purposes. Excel is really VERY good at taking a single table and producing a summary report. The Pivot Table, with its cross-tabulated summary of monthly transactions per client (for example) is something you're already familiar with. It's also possible that you'd be better off using a single table for all transactions, keyed (obviously) to each client's account number(s), but still a single table for all of them, and then let Excel do it's trick of separating out the relevant transactions (or whatever) per client......i.e., let Excel do the "heavy lifting" of extracting data based on a few parameters, rather than having to search for each client's separate sheet every time you want to enter something pertinent.
I'm not saying that's a foregone conclusion, but I do want to make sure you've considered the possibility rather than assuming that, because you'll want OUTPUT that is client specific, that means you also need to have the INPUT be on client specific sheets. That premise is not a necessary (or, for that matter, helpful) way to approach your design.
So, if you can forgive the impertinence of my asking you to explain your business goals here rather than just helping you do what you asked, my goal (and I think that of others on this site, many of whom are far more expert with such things as Power Query than I) is to help you come up with the best design, and to do that we need to ask for a description of the bigger context within which you're operating.
- dlucas980Copper Contributor
I attached an example, I am trying to populate information for about 200 accounts (arranged horizontally in the sheet MasterList). I have a list of about 45 items to populate (the example has 5 items). I want to automatically populate individual sheets like the two sheets in the example for all 200 accounts.
I hope this helps.
Thanks for your input!- mathetesGold Contributor
Bear with me please.
You haven't explained what you're going to do with those individual sheets.
So I'm still going to push to have two basic databases:
- one which is the account numbers and individual data corresponding to each account (you'll see I reorganized yours)
- the other being--Well, here's where I was asking you what the larger context is--for the time being I'm going to assume it would contain such things as transaction history, deposits, withdrawals, whatever; it could also contain actions/transactions of other types..essentially a history of the accounts in your custody. I haven't done anything to mock up this, because I wanted to find out what it is you anticipate doing with the individual sheets. FYI, it wold be very easy using the new FILTER function to list any accounts deposits and withdrawals (and other transactions) on the page, extracting them from a comprehensive list of all clients' account histories, putting them in date (or other category) order.......
My point is that from those two databases (which are all encompassing) you could produce individual sheets on an ad hoc basis.
So I've illustrated that with the example data you've given me. What I'd like you to do with this is play around a bit, seeing how you can add new accounts and have the drop down list on the "Indiv" tab automatically include those new account numbers and therefore easily be populated by the additional data. [I didn't provide room for the second street address, but that's easily handled]
Instead of current account value I created a field called Opening Account Value or something to that effect. Current value is a volatile number, and would be produced in that ad hoc page, based on transaction history (assuming that's what you want).
But please tell me what it is you are going to want those individual pages to show, and then we can talk about whether this kind of design will work.
A caveat: that data validation list that is used to populate the options in the drop down box makes use of the UNIQUE and SORT functions which are only available in the most recent release of Excel, so if they're not working for you, then we'll have to do something else...(or get you that newest Excel)