Use a sheet name based on Column Value - excel

Using Google Sheets or Excel:
I have columns (B) with Stock symbols, e.g.: B2=GOOG, B3=AAPL, B4= MSFT
I have Sheets named with these same stock symbols respectively. Eg: Sheet2: GOOG, Sheet3: AAPL, etc
I have a formula on Sheet1 that does some computation using data in other sheets. Eg: K2=((GOOG!B2+GOOG!B5)/GOOG!B24)
----I want to automate grabbing the correct sheet name based on column B without manually typing in the sheet name into this formula.----
Is there a way to input the sheet name in this formula K2=((GOOG!B2+GOOG!B5)/GOOG!B24) based on column B in sheet1?
Conceptually something like K2=((*indirectB2*!B2+*indirectB2*!B5)/*indirectB2*!B24)
In other words, how does one input a sheet name into a formula based on a string in a column
My example image is a tad different than mentioned above but same idea:

I solved this using =INDIRECT("'"&B4&"'!$B$2")+INDIRECT("'"&B4&"'!$B$5"))/INDIRECT("'"&B4&"'!$B$24")

Would K4=((B4&!C43+B4&!B5)/B4&!B24) work?

Related

How to merge/copy a single column's values in one sheet into another sheet based on the values of a column using excel?

I have two excel spreadsheets (that I can put onto two separate sheets within one sheet, one call A, and one called B).
Spreadsheet A/Or Sheet A
NAME,SPORT
Jordan,Tennis
Jordan,Basketball
Jess,Tennis
Mike,Baseball
Spreadsheet B/Or Sheet B
NAME,AGE
Jorden,5
Jess, 6
Mike, 10
I want to make it so that I can merge the two spreadsheets such that the "Age" column is added to Sheet A with the resulting spreadsheet:
NAME,SPORT,AGE
Jordan,Tennis,5
Jordan,Basketball,5
Jess,Tennis,6
Mike,Baseball,10
How can I do this?
Assume there is an exact match for names in Spreadsheet B to Spreadsheet A (first names only, no need to worry about last names).
Range of values could be variable, but if it's just a matter of making sure the range is updated as new values are put in manually, it's okay. Unless there is a smarter way.
In sheet A, cell C2 :
=INDEX('Sheet B'!$B$2:$B$4,MATCH('Sheet A'!A2,'Sheet B'!$A$2:$A$4,0))
Things to consider :
Is the size of your data variable ? > Do you need to adapt the look up range ?
Will you have duplicates in the names ? > What if two different kids are called "Jordan"

Sumproduct in excel using external data source

I am trying to calculate some data in a excel using external excel file. My formula is like;
=SUMPRODUCT(--('[Stock Register.xlsx]Stock Code 1'!$E$3:$E$500="Issued to Sanitary Syndicate"),'[Stock Register.xlsx]Stock Code 1'!$C$3:$C$500)
This works fine for me. But I need the sheet (Stock Code 1) being changed automatically when dragging or pasting on the next rows.
I am using it a new workbook using external data source (Stock Register.xlsx). Stock Register consisting of 570 sheets and for each sheets I need to display results in that New Workbook in cell (C1) using above formula and drag it to cell (C70).
You can add two columns before the SUMPRODUCT.
First column, say this is in column B, will need to have CONCATENATE to the external spreadsheet that you want to link to. For example:
=CONCATENATE("[Stock Register.xlsx]Stock Code",ROW(A1),"!$E$3:$E$500")
This should give you [Stock Register.xlsx]Stock Code 1!$E$3:$E$500.
Same thing for the second column that you want for $C$3:$C$500 so you can get [Stock Register.xlsx]Stock Code 1!$C$3:$C$500.
Then the third column, say this is in column D, will be the SUMPRODUCT formula that with INDIRECT. And here you go:
=SUMPRODUCT(--(INDIRECT(B1)="Issued to Sanitary Syndicate"),INDIRECT(C1))
Hope this helps.
P.S. One thing I noticed when combining all three into one column, the formula wouldn't work. Someone probably can come up a better way but to have a reference address sit next to the result may benefit you to debug down the road. Just a thought.
UPDATED:
Okay, I was able to recreate what I described below. Maybe it is easier to show you in screenshots:
See I created three sheets in Stock Register.xlsx file, Stock Code 1 sheet looks like below that values under column C and descriptions under column E.
And another spreadsheet called Results.xlsx. Column B has a formula of =CONCATENATE("'[Stock Register.xlsx]Stock Code ",ROW(A1),"'!$E$3:$E$500").
In this picture, Stock Code 2 sheet looks like below.
Column C in Results.xlsx spreadsheet has a formula of =CONCATENATE("'[Stock Register.xlsx]Stock Code ",ROW(A1),"'!$C$3:$C$500").
In this picture, Stock Code 3 sheet looks like below.
Column D in Results.xlsx spreadsheet has a formula of =SUMPRODUCT(--(INDIRECT(B1)="Issued to Sanitary Syndicate"),INDIRECT(C1)).
Try again and let me know.

How can I use a drop down list to change the reference in a formula in Excel

I have a workbook that has many sheets. Most of the sheets contain raw data. One sheet referred to as "Quick Stats" contains a bunch of various tables that take the raw data and give it meaning, such as: how many tests were taken in January; which teacher gave out the most tests; etc.). I'd really like to be able to display the stats for any given period without having to create additional sheets or tables. I'd like to select a period and have all the formulas on my stats sheet display values from the sheet that contains the data for that period.
Is there a way to have a cell (maybe a cell with a drop down list?) whose content becomes the reference point in the formulas?
For instance my sheets are named AY 13-14 (aka. academic year 2013-2014).
So if I have a formula like below
=SUM('AY 13-14'!C:C)
how can I make the sheet name of 'AY 13-14'! be the result of the value of a cell and have the formula reference the correct sheet?
Is this even possible?
Your formula will have to use INDIRECT reference based on the value of the cell with the drop down list.
For example: if you have your drop down list in the cell QuickStats!A1, then your formula will be
=SUM(INDIRECT(QuickStats!A1 & "!C:C"))
(Your drop down list would have to contain names of data sheets, e.g. AY 13-14 etc)

Combining Like Data in Excel

So here is my situation: I need to take two spreadsheets in excel and combine the data together so that any additional data is paired up with common data between the cells. Here's an example of what I mean.
Sheet 1
1234567, JOHN, DOE, 1234567.JPG
Sheet 2
JOHN, DOE, 6634
First and Last names are common data, but the number in the second sheet does not exist in the first. The user list in both sheets are slightly different from each other so I can't simply alphabetize the names and move the additional column over. I have about 500 users to go through and may have to use what ever solution I come up with for similar lists of users.
Any assistance would be great.
There's various techniques you can use to combine data but you'll have to be a bit more specific. For example is there a fixed number of columns that sheet 1 doesn't have that sheet 2 does?
The basic technique would be to create some sort of unique identifier, perhaps by concatanating the names together in both sheets? that way you can use VLOOKUP to put all the missing data in one sheet into the other
Not sure I understood "I cant alphabetize the names". However, if the names have the same spelling i.e John is John in both sheets you can concatenate John and Doe in sheet 1 and do same in sheet 2 and use a vlookup function. Something like
A=cellcontainingJohn&CellcontainingDoe in sheet1
B=cellcontainingJohn&CellcontainingDoe in sheet2
C= Vlookup(A,rangeforB,columnnumber)
Here's what I would do:
Select the sheet into which you want to pull data from the other. I'll assume we're pulling data from sheet 2 into sheet 1.
In sheet 2, insert a column to the left of what you have already. JOHN is now in column B, DOE in column C, and 6634 in column D.
In sheet 2, column A, row 2 (assuming you have a row of column headers) which is currently empty, use the formula
=CONCATENATE(B2,C2)
Now, head back over to sheet 1. Let's assume you also have a row of column headers in sheet 1, so the cell immediately to the right of your 1234567.jpb is E2 and it's empty. In E2, use the following formula
=IFERROR(VLOOKUP(B2&C2,'Sheet 2'!$A:$D,4,FALSE),"")
That should give you what you're asking for, if I understand your question correctly.

How do I get my formula to always reference to the last sheet?

I currently have 2 worksheets in my excel file.
The first sheet is known as the Summary page, which displays an summary result of the second sheet.
The second sheet is known as the raw data. An example would be a column named Fruits.
Apple
Apple
Apple
Banana
Banana
Pear
In the first sheet, I would have a formula that counts the number of time the respective fruits appear and the result will be displayed in different cells.
=COUNTIF(Fruits!A2:A7,"Apple")
=COUNTIF(Fruits!A2:A7,"Banana")
What I wanna do is, is it possible for me to program the formula such that everytime I add a new sheet of raw data (3rd sheet), the statistics on the first sheet is able to reference to the latest sheet to get the information.
(Assuming that the positioning of the data and all are the same as the second sheet.)
What I have done so far is to come out with a function GETLASTWSNAME() which is able to always retrieve the name of the last worksheet. but it seems kinda impossible for me to nest the function within the countif formula itself.
=COUNTIF((GETLASTWSNAME())!A2:A7,"Apple)
The above formula is how i want my formula to work, but sadly excel does not allow me to do that.
Any comments would be appreciated. Thanks!
You can use the XLM/Range Name workaround for this and not VBA if you prefer
Define a range name, wshNames to hold the array of sheet names
=RIGHT(GET.WORKBOOK(1),LEN(GET.WORKBOOK(1))-FIND("]",GET.WORKBOOK(1)))
Uses David Hager's technique
Use this Excel formula to extract the last sheet name from the array of sheet names
=INDEX(wshNames,COUNTA(wshNames)+RAND()*0)
This formula says look at all the sheets, then return the last (using the COUNTA). The RAND()*0) portion ensures that the formula is volatile and updates when Excel does
If you do use VBA you will need to ensure your GETLASTWSNAME function is volatile, i.e. it gets updated when changes occur.
=COUNTIF(INDIRECT(GETLASTWSNAME() & "!A2:A7"),"Apple")
In Excel with spill function and the new Sequence() you can list all your sheet names with the same technique just from one cell! First to last or last to first, your choice. With Transpose you get a column header for each sheet (Obs volatile).
After defining the named formula wshNames as told by Tomalak ( thanks for the tip ) I used:
=INDEX(wshNames;COUNTA(wshNames)+1-SEQUENCE(COUNTA(wshNames);1;COUNTA(wshNames);-1))
my Excel is using ";" as a separator, you may have to change the semicolons with a comma
Rolf H

Resources