Excel formulas

Copper Contributor

I am trying to pull a row number that is associated with a student record into a formula in a second sheet.  The names are alphabetical in one and by classroom in the other

 

20 Replies
I assume you're meaning "Row" as in "What row of seats does this student sit in?" Without seeing what your sheets actually look like, it's hard to write the formula. But it occurs to me that you don't really need two sheets in order to have one sorted alphabetically, another by classroom. Excel has a "Sort" function, under Data...Sort, and that allows you to sort by any of the columns in the list. So you could have an alphabetical sort and then switch to classroom sort of the same list AND that list could include the Row data that apparently is in the one but not in the other. For some reason I'm not seeing the ability to upload a sample sheet right now as I write this reply... but if you highlight a list that includes two or three columns and then go to the "Data" menu item at the top of your screen, click on it, and you'll see "Sort" as one of your options. Clicking on that will give you the choice of columns to sort by, whether increasing or decreasing. You can have secondary and tertiary sorts..... Write back if this doesn't make sense.

@madgateI wasn't able to download your sample for some reason...got a bunch of error and warning messages. but here finally is a quick example of a sortable list that should illustrate another possible solution. You can sort this by name OR by classroom....

 

There's a brief explanatory comment on the sheet

@mathetes thank you.  No i have them sorted ok im  just trying to pull the row number of the student from the lunch sheet to the formula in the alphabetized balance sheet.  I can do it manually by finding the student in one and putting it in the formula  it just takes time to do 300 of them

i attached a copy of my spreadsheet 

@mathetes 

Last NameFirst NameTeacher RoomSchool IDFamily TotalTotal Lunches SeptemberTotal Lunch Spent SeptemberTotal Milk Total Milk   Spent SeptemberTotal  Family Spent SeptemberTotal  Deposits SeptemberDate  Deposits SeptemberEnd of Month Balance
AdgateMarymccoolk0-2 $10.000$0.000$0.00$0.00  $10.00
AdamsAmosO'ReillyK0-1 $0.000$0.000$0.00$0.00$40.00Monday, June 3, 2019$40.00
AndersonDrewGriswald6-16 $23.001$3.001$0.50$3.50  $19.50
AndrewsOwenBarrowsK1-5 $33.500$0.000$0.00$0.00  $33.50

@mathetes  this is the formula in the balance sheet =InputSept19!I388 and it pulls from the input sheet =InputSept19!I1388   so i was just looking for an easy way to populate the row (388) in this case instead of me having to manually enter it into the formula

thanks

Mary

 

(My point on the matter of sorting was to challenge the fact that you have two sheets, one sorted one way, the other another. Why two sheets?)

I was finally able to download your sample sheets this time. I'll have to say (in all honesty) that I'd most likely take a totally different approach (I think) to designing your "InputSept19" sheet. It looks like you're trying to do several things at once, possibly....track what each student has ordered (or how much to charge on a school bill) or some such.....AND track how many different entrees get ordered on different days of the month, for Kitchen Inventory purposes. So let me leave it at that for now and try to address your immediate question.

The VLOOKUP function might accomplish what you're trying to do. You'd use the SchoolID field as the key identifier in the formula--it's unique to each student, where the name is not necessarily unique--and then retrieve the data in the row and column you want by means of that.

HOWEVER the way your INPUT sheet is designed is not ideal for that purpose, (or at least it's not clear to me what the underlying pattern is, and how it might be made consistent from month to month. Is it only column I (as in I388) that you are looking for. In your live spreadsheet, it seemed to me you were pulling from column AQ, which carries the heading "Total Milk" ... so I'm asking is that always what you want? AQ4, then AQ5, then AQ6,....? If so, VLOOKUP could work.

But before we go forward (unless some other reader here has another idea) could you spend some time talking about what your underlying purpose is with these two spreadsheets? It looks like you're tracking something to do with lunch orders per student, but at what level of detail, etc.

The more complete your description of the "business need" here, the more we can help in the design, which might mean more than simply giving you a formula. You want to do more than put a bandage on the problem; you want to solve the underlying need.

@mathetes thank you so much!  I'll take all the help I can get.  One of my workers created this spreadsheet years ago and it has worked for me for the past few years.  Yes in the input sheet I enter in the lunches and the drinks that students consume on a daily basis.  The total milk and the total lunch number is then carried over to the SeptBalance sheet which deducts the amounts from each families account and then I get alerted when their account is low and I send them an email.  Does that help I hope.

Mary

@madgateOK, Mary. I hope this helps. I've incorporated the VLOOKUP function to accomplish your goal. There are also some fairly extensive comments in the form of text boxes inserted into your spreadsheet to explain what I've done and how it works. I'm sure you'll still have questions, so feel free to come back. But try to play around a bit with both that VLOOKUP function AND the "named range" concept. I tried to explain both.

 

A question for you, though: this workbook--the INPUT sheet in particular--bears all the marks of a process that was done on paper for some time before anybody thought of using Excel...and all that was done was to copy the paper format (I envision a big sheet of green accounting paper), using Excel solely to do the basic math, adding and subtracting, maybe a little multiplication along the way. Unless you really need to track all of these by day and by type of lunch (!!) it would seem to me that that initial collection of "input" data could be radically simplified. Before I make specific recommendations, though, I'd want to know whether you DO need to know what was served for lunch each day, and whether (for that matter) you need to know which specific days each student HAD lunch and HAD milk.

How does that "1" get entered in the InputSept sheet in the first place? Is somebody sitting in the lunch room as the students come through the line, entering a 1 in the column for the day? Same for milk?

@mathetes thank you again.  I'll look at it tomorrow  And i input the 1 into the spreadsheet from the lunch/milk cards that the students put in a bowl.  I do need the totals by day and at the end of the month I need to report my numbers.

I'll get back to you tomorrow!

@madgate    Here's a "New & Improved" version. I've changed the Input sheet in particular to make it both prettier and, I trust, easier to use. All you need to do on the dates across the top, for instance, is enter the first school day of the month, and all the rest are calculated, skipping weekends automatically.

 

I've also used the "freeze panes" feature, so that you're not lost off at the right, not being able to see the names of the students. Now the input column for lunch or milk is visible on the screen close to the list of names. It could be made even closer....

 

Take a look and come back with any of your questions.

@mathetes ive been looking at what you sent me  the only place i'm having issues is with the named range   i think im doing something wrong

thanks

Mary

 

@madgate   First, have you opened the newest one that I sent? (You might still be having issues; I just want to make sure you've seen that "New & Improved" version.

 

Second, can you describe the issues a bit more precisely. Have you been trying to create a named range and just not finding the menu spot....or are you just not making sense of what it is and why use it?

 

If/when you start using this system in real life, you'll be adding more names, I'm sure...more School IDs, etc.,, and when that happens the range will need to be enlarged to cover the entire student body. I only recently myself learned a way to do that "dynamically" so you don't have to do it by re-entering cell addresses.

 

But let's first just see if we can get you to the point of understanding VLOOKUP using a named range as the table of data from which you extract the numbers you want.

@mathetes I didnt see the new and improved and it looks awesome!  I know if I had time I couldve made it look pretty but I so appreciate your improvements.  When I read your notes about the named range i wasnt sure if the  rows you put in the notes were correct .  I was a little confused.

"LunchPurchases" is a name I assigned to the range in the InputSept19 sheet beginning with  column I, which contains the SchoolID for the student, and goes through Column AQ. I,e., it's almost that entire spreadsheet where you have the information. You could, in place of "LunchPurchases" put in $I$3:$AQ$17 but using a named range makes that easier to read the formula, to make sense of what's happening.

Column E is the school id in the inputSept19 sheet.  I understand the formula but my range gave me an error.  Thanks so much!

Woops...that $I$3 was a mistake on MY part. I'm sorry. It should have read $E$3....

but please use the named range tool.

If that was your only issue, that's great. You'll see that the "range" identified in the New & Improved is different, much smaller, because of the different layout.

If that works for you, I"ll make one more change which will allow the named range to grow as you add names. Let me know if you'd like that.

@madgate   Here, Mary, is an even Newer & More Improved... the only difference in this newest one is that I've added a feature to enable the named range "LunchPurchases" to grow as student names and IDs get added. I did this only up to a max of 100. If in fact you have more, all you'd need to do is change the =COUNTA formula in cell B2 to a larger number......

 

So try this one out next month and let's see how it works. Other than the real names of students, it's all set for November.

 

John

@mathetes Awesome!  I got the range to work in my original one   Yours looks great and can't wait to use it  I can't thank you enough for all your help.  Your a godsend :)

Mary

You're very welcome, Mary. I love using Excel (much prefer designing a spreadsheet to playing computer/video games)...and am learning since joining this site last week, just a day or two before you did, that Excel has added features in the last decade or more that I didn't know about (I retired in 2002 and have continued using Excel personally, but not keeping up on all the changes)...
Anyway, feel free to come back with questions about the solution I've given you. Depending on the volume of lunch purchases, the number of students, etc., there are surely more elegant ways to meet your needs. I have some ideas, but they'd involve major changes that may not be worth it in your situation.
John (mathetes)

@mathetes my school has a new billing program which isn't the end all be all so i am trying to get my spreadsheet working which has always worked great for me.  Lot of catch up but it will be worth it.  I also actually spoke to soon.  When i cut and pasted the VLOOKUP formula I am seeing a few N/A's   Can't figure out where the error is

 

If you're only getting a "few N/As" that suggests possibly the SchoolIDs aren't being found for those few students. Off hand I can't think of another cause for that. One of the essential parts of a viable database is a reliable and consistent "key"--otherwise known as a unique identifier. Sometimes, even as simple a matter as an extra (but invisible) space in the field of one or the other of the two spreadsheets entries for that field..... so check the SchoolID field for those few N/A cases...to make sure they're identical even to the point of having no "trailing space" after the last digit. The VLOOKUP is looking for an EXACT match.