Displaying a portion of a table in a separate worksheet - excel

On my first worksheet in the workbook, I have a large table with multiple columns and rows (roughly a 1000 rows and 20 columns).
I was wondering if it is possible to display part of this table in another worksheet in the workbook based on the criteria from one of the columns in the main table.
To help explain this, I will use an example from the actual workbook.
On worksheet 1 (called General Employee Info which is the main table), in Column A each row has a unique number identifying an employee (each employee has their own ID number).
Column B holds their office location (a city/municipality). Column C holds the state the office is in. Column D holds their salary amount per year.
There are multiple more columns with this type of employee information, which needs no further explanation.
My question is, can I label Sheet 2 in the workbook "New York State" and have that sheet display all the same information as Sheet 1 (all the same columns) but only display the employees that work in the state of New York?
And then have another sheet labelled "California" and have only the employees that work in California on that sheet and so on... In other words, have a separate sheet for each state.
It's essentially like filtering the main table using the State column to show only one state, but I want the results in a separate sheet instead of filtering the main table which holds all the information.
I was thinking of using a pivot table in each new sheet, but am not sure that's the right approach.
Is this possible? I hope I was clear in explaining the problem.

I really recommend using the excel tables feature if you are using Excel 2013 or later as a starting point. Tables rock for many reasons, including making your sheets more readable for users, and making formulas for things like INDEX/MATCH much less error prone.
Once the tables are in place with the main data, to subset I use the data modeling capability to link back to those tables.
These steps in Excel 2013 - version active around 2018. It's changed in Office 365 (see below)
create a sheet, or go where you want the table in your current sheet.
click the 'data' tab and select "connections" in the connections section.
from there select the drop down on the add button and select Add to Data Model..
Connections Dialog
Click the tables tab. Click the table you want.
now close the dialog
on the data tab, click Existing Connections in the "get external connections" of the data tab.
Click the Table tab
Select the table you want
Select the table radio button
hit return (or new sheet or a different cell if that's what you want)
poof your table from another sheet is now reflected in the current worksheet.
At this point you can subset using data slicing, hide columns, insert new columns with new formulas on the right or left edges of the table, etc.
You do have to refresh this separately using the 'refresh all' button on the tool bar.
In Excel as of October 2019 as (Thank you Josh for point this out!) It's gotten better as they include some of the 'power' tools in excel, and made a toolbar item that gets to the functions. Specifically:
Create a Table with the source data by selecting the data in the sheet, and using insert Table.
Select the Table
On the Data Tab click the small icon in the lower middle with the tooltip "from Table/Range"
This will Open the Power Query Editor. Microsoft has a tutorial; but it looks a little different now
After you've built your query; press "Close and Load" in the editor. Without options it will create a new sheet. If you choose the option with the ellipsis you have a few other options.

There is a variation of what you are trying to do here : http://www.get-digital-help.com/2009/09/28/extract-all-rows-from-a-range-that-meet-criteria-in-one-column-in-excel/
If all your data is on Sheet1 and you define a range (CTRL F3) which contains all the elements called [tbl]
In Sheet2 In cell A1 enter the column number that you are searching Sheet1
In Sheet2 in cell B1 enter the search criteria (ie, the State you want to filter by)
From Cell A2 to Z1000 (for example) enter the following array formula (So enter using CTRL SHIFT RETURN)
=INDEX(tbl, SMALL(IF((INDEX(tbl, , $A$1, 1)=$B$1), ROW(tbl)-MIN(ROW(tbl))+1, ""), ROWS(A2:$A$2)), , 1)
One key point to note in the execution of this is to create the array for the first row first, CTRL SHIFT RETURN to create it, then drag it down. Doing it in the wrong order won't increment the row counter at the end of the function properly. Just follow the instructions at the link at the start of this post and your should get it.

Related

Two tables with no unique values that I need to match and return value based on date range and zipcode fields

I have two sets of data; the first (Wind Claims) contains a StartDate, EndDate, and Zip Code field. The second (PLRB Wind) contains a Date, Zip Code, and Wind Speed field.
My goal is to get the Wind Speed from the PLRB Wind tab to the Wind Claims tab if the Date from the PLRB Wind tab is between the StartDate and EndDate on the wind Claims tab AND the Zip Code from the PLRB Wind tab matches the Zip Code on the Wind Claims tab. The point is to identify the wind speed where damage was reported.
I have tried a couple formulas; this one I actually got results but only 1227 out of 16822. I wouldnt expect to have a 100% match but definitely much more than what I am getting. I think the reason is because this formula is looking for the specific date and not looking at the date range:
=XLOOKUP(Z2&N2,'PLRB Wind'!$I$2:$I$78525&'PLRB Wind'!$D$2:$D$78525,'PLRB Wind'!$M$2:$M$78525,"")
I also tried an Index Match (this is just the Match piece of the formula)
=MATCH(1,IF('PLRB Wind'!D2>=$B$2:$B$16823,IF('PLRB Wind'!D2<='Wind Claims'!$C$2:$C$16823,IF('PLRB Wind'!I2='Wind Claims'!$Z$2:$Z$16823,1))),0)
Thank you in advance for looking at this. I appreciate any help you might be able to provide!
I'd use power query for this. Do you know what power queries are?  I was upset when I found out because of all the useful ways I could have been using it before.
You might feel differently, though. Create a new copy of your workbook for this just in case you hate it. :-)
In the "Data" ribbon of Excel, in the Get & Transform section, there's a "From Table" button. Highlight your PLRB table (including the column titles) and click that "From Table" button to create a new query from it. It will create the table and the query.
A power query editor window will pop up, presenting your query as two steps, listed in the middle of the right sidebar. The first step is to get the information from your worksheet. The second step changes the data types. Click the icon to the left of each date column's title to change the type from datetime to date because why not. On the right sidebar, change the query name to PLRB.
Now click "Close & Load" on the home ribbon. It will create a new tab with the results of your table. Leave it for now. You can delete that tab later and it won't delete the query.
So, back to your worksheet, highlight the column-title row and data rows for first three columns of the wind claims table. Create another query from table. Call it WindClaimsInput. Again, correct the datetime columns to date columns
OKAY, so now you have two queries. They both read from your workbook but they could have been from another file or text file, etc. If you like this solution then your final form might be a worksheet that doesn't actually have any source data in it, just queries that gets the raw data from elsewhere and a tab that presents the third query we're about to make.
Now for the fun part.
While still in the power query editor editing your WindClaimsInput query, near the left edge of the "Home" ribbon there's a button named "manage...". Click it, then click "Reference" to create a third query that starts with the old one. Remember, queries are only instructions. We aren't copying data until we run the queries.
Now, find the button to add a column. It should open a dialog box asking the column name and formula. Name it "PLRB" and use this formula: Table.SelectRows(PLRB, (r) => (r[Date] >= [CATFromDt] and r[Date] <= [CATThruDt] and r[ZipCode] = [ClaimZip])) Table.SelectRows is a power query function that takes two arguments:
The table (or query that returns a table), and,
A function to run on each record (aka row) of the table and return true/false. In this case, we created a function that takes one argument (r) and returns true or false.
So the above formula says "Give me a table of all rows in PLRB for the given ClaimZip zip code that also has a Date between CATFromDt and CATThruDt." Since it's a column formula, it runs once per row in. Wind Claims.
Now you have a table where the last column is another table! Specifically, the rows from PLRB that are relevant for that Wind claims row. You can single-click on any of those cells in that last column to see the subtable.
To right of the last column's title will be a little "expand" icon. Click it, choose to aggregate by max wind speed. (The right edge of the "wind speed" choice will let you change it to maximum, or average, or whatever you like.) Unclick "Use original column name as prefix". Click okay. Don't worry, you can delete this new step and try again if I didn't describe it well.
Hit "Close and Load" to see it in your workbook. If it looks right, great! Otherwise, feel free to go back and edit some more.
And now you're done! Unlike formulas it doesn't automatically refresh but when you want to refresh your output based on your input tables you can refresh that query or, in the "Data" ribbon you can click "refresh all".
In the data ribbon of Excel, in the "Get & Transform" section, there's a "Show Queries" button that toggles a sidebar that displays your queries you've made. You probably only want to keep loading your third query, so you can change the "Load to..." of the other two queries to "Connection Only".
Sorry I can't do screenshots right now.

Excel populate table from same workbook

I have a table on Sheet1. I want to pull in data into this table based on entry in another tab.
For example, I have a table
based on information in other tabs, I want to populate the Score column.
Can this be accomplished using SQL query or Powerquery (pseudocode- Select "Score" from other tab where Name = Jack )
I can look for events in VBA when if data is entered in the other tabs it can grab it and paste it in this table but it seems messy.
The reason I want to do this is, there are multiple tabs where people can enter their Scores. They cannot enter this in the main tab otherwise I wouldn't have a problem.
Load all datasets from your worksheet to PowerQuery and keep them as connections only (w/o loading to worksheet) except the one that you want to populate with the data in the end. After loading you can merge different datasets using selected columns as the key for joining. The result of the merge would be a table from which you could retrieve particular columns of interest.

Microsoft Excel. How to put all tables from all lists to a single list

Is it possible somehow to do the following in Microsoft Excel?
Every list has a single table with its own Header:
Table may be of any size, and number of such lists is unknown in advance.
I need to gather all those tables in the very first list which is called "Main" so that each table just followed by another like this:
I need it only for printing, so sorting and another stuff like this is unnecessary.
Microsoft Excel - 2019.
I think you can achieve what you are after using named ranges per this video.
The ranges are then accessible from the dropdown to the left of the formula bar.
I find it easy to select area of tables first, then define a named range based on currently selected area, rather than entering it in the prompt per the video.
1. Insert -> Name -> Define Name
If you have a workbook with multiple sheets you can define names on any sheet, So lets's say table1 was in sheet1, and table2 in sheet2. If sheet1 was the active sheet, you could still select the named range of table2, and Excel will automatically flip sheets for you and select that area as if you had just highlighted the region.
Later when it comes to printing, select the named area, and the say
2. File -> Print Area -> Set Print Area
Then do:
3. Print and instead of selecting Active Sheet use Selection
(I am talking about doing it on a Mac V16.22 - but should be similar on Windows too)
EDIT:
There is IMPORTRANGE in Google Sheets.
Not sure if something similar in Excel was what you were after.
So take a look at this too.

How to select entire excel spreadsheet for pivot table?

I want to be able to select and reference all of the tabs in my excel spreadsheet (to get totals of everything), but the data source only allows one tab to be selected... is there a way to select and use the entire workbook in the pivot table?
Thank you!
You actually just have a data formatting problem. You're using tabs to separate devices by departments instead of simply creating a department field/column and putting everything in one tab. The data was likely delivered to you that way, but don't let the delivery format define the true working format of the data.
Combine everything in one tab, and then you'll be able to use the data in a pivot table just fine.
If you have more data than will fit in a tab, put it in a database such as MS Access, MS SQLServer or mySQL, and then tell excel to use the database as the pivot table source.
I think Jonathan M has the best answer, but here's a way to do it using SQL that I've used successfully.
I don't know any easy way of doing this, but you could write a macro to copy and paste all your existing sheets onto a single new sheet (assuming there's enough room on a single sheet).
In 2007 Multiple Consolidated Ranges isn't in the default pivot table window. You need to create your pivot table, click on it, hit Alt + D, then P. Click back to step one and you'll have the option for multiple consolidated ranges.
Select the data on any of the one sheet and hit Alt D > P. It will show you Step 1 of 3 for PivotTable Wizard. Now select Multiple Consolidation Ranges and hit Next.
Select and add different fields from different tabs and it will create a consolidated range for your PivotTable and then you can run your PivotTable based on data located on different tabs of sheet at the same time.
Hope it helps.

Macro to copy select rows to another worksheet and sort by month

Does anyone have a macro that will take data from a compiled list, sort out a particular month, the paste only the sorted month into a new worksheet?
What I am setting up is a log where the samples are placed in the "Full List" by all employees and then when the boss wants to view only a certain months samples say January, he will be able to click the January button and it brings him to a worksheet which has copied only the "January" dated samples from the Full List worksheet into a new location for viewing. Since the data continually comes in it would need to sort and select new data each time.
Thanks for your help in advance!
I just made a mock workbook as you described, using the .advancedfilter function.
Only resource I used was this: http://www.vbaexpress.com/kb/getarticle.php?kb_id=567
You should be able to figure it out from that, and from the example spreadsheet you can download from the bottom. If you can't, you're in over your head I'm afraid :)
This can be done without VBA by creating a pivot table grouped by month. When you double click on the value for a particular month, a new sheet will automatically be created and populated with a filtered set of the data for that month.
Select your data then click on 'Data - PivotTable and PivotChart Report'
Click on the Next button, the Next button again and then the Finish button
Drag your date field into the row fields
Drag the employee name into the data item section
Right click on the row fields containing the date and select 'Group and Show detail - Group'
Set a start and end date and choose to group by months
Now double clicking on any amount in the data item area will create a new sheet showing the data that was used to generate the number.
As your data is continually changing, create a Dynamic Named Range using 'Insert - Name - Define' to use as the pivot table range. The formula for the Dynamic Named Range would look similar to this:
=OFFSET(Sheet1!$A$1,0,0,COUNTA(Sheet1!A:A),3)
If you are using Excel 2007, then mark your data as a table (Ctrl-T) and use this as the basis for a pivot table to achieve the same effect.

Resources