I want to use an excel spreadsheet to lottery off a set of items amongst multiple contenders. I made a sheet with a column for the item and one for each contender. On each row, the first column has the items name and each user puts a "y" in his cell if he has interest in that item:
Item -A-B-C-D-E-F-G-
Foo - -Y- -Y- -Y- -
Bar -Y-Y-Y- - - - -
Roll -Y- -Y-Y- - -Y-
I then added a column which counted the amount of contenders with a formula like:
COUNTA(Table2[#[A]:[G]])
And another column to choose a random number amongst the contenders with a formula like:
=CEILING.MATH( RAND()*[Amount of contenders cell])
The issue is: Once I have the index of the contender who won, how can I display the name of the winning contender based on the index of which Y was selected?
I solved this by making another table right next to the first table with a column for each contender. The value of each cell = how many "Y" (or non-blank cells) occur upto and including the current contender. The formula for each cell is:
The first column simply is equal to if the corresponding cell is blank: 0 otherwise: 1
=IF(ISBLANK(Table2[#A]),0,1)
And the subsequent columns equal to the previous column + the formula above:
=IF(ISBLANK(Table2[#B]),0,1)+K2
I now have a soon-to-be-hidden table corresponding my original table which looks like this;
A-B-C-D-E-F-G
0-1-1-2-2-3-3
1-2-3-3-3-3-3
1-1-2-3-3-3-4
Once I have this table, I can successfully use match and index to get the name of the 3rd contender for the given row. First I get the absolute index of the n-th non-blank column (the last parameter: 0 indicates that I want an exact match, which gives me the first occurrence of "n" in my helper-table for that row:
=MATCH(Table2[#[Snapshot of lottery results]],K2:P2,0)
And then using that index, I can get the name of the winning contestant (where B1:H1 contains the column names and the cell at column J:current row contains the decision index:
=INDEX($B$1:$H$1,1,IF(J2>0,J2,""))
Related
I've faced huge problem with my macro. I have data that contains colums with quantities and values of stock like this:
What I'm trying to achieve is:
to go through every row until the very last, locate quantity (colums with Q letter) and values (colums with V letters) below 0, then adding these quantities below zero to the maximum quantity within the row and adding these values below 0.
to find values within age category for every row that have no corresponding quantity (see cell B4 as example) and add these values to the maximum value within the row.
Why VBA for something you can achieve with a formula?
Let me show you how I calculate the maximum of a list of cells, referring to a column, whose name starts with a "V":
=MAXIFS(A2:F2,A1:F1,"V*")
Screenshot:
Explanation:
Take the maximum of the values on the second row (A2:F2)
The criteria you need to take into account refer to the first row (A1:F1)
The criteria is that it should start with a "V".
screen shot of excel
Hello,
I have 3 columns in my excel sheet. Column A is item number, Column B is file Name, Column C is the date/time that file was modified(it is called matched in excel). I created a column D called versioning by comparing date and time of files with the same item number, right now I am doing this manually, Is it possible that it can be automated?
Thanks in advance!
Assuming your data has column headings in row 1, so data begins on row 2 and version begins on cell D2 and, just say your data stretches down to, say, row 100, you could use the following formula in cell D2:
D2: =COUNTIFS($A$2:$A$100,A2,$C$2:$C$100,"<="&C2)
Basically, you're saying For every file with the same Item number, how many have a date/time less than or equal to this row's?
That will, in effect, give you a version number.
As requested in the comment, to explain this formula in a bit greater depth, let's break it down:
Heading Match:
CountIfs($A$2:$A$100,A2:
This portion is saying "Only count if the value in $A$2:$A$100 = the value in A2" - Therefore, only count rows where the item number is the same as the one in the current row
Versioning:
CountIfs($C$2:$C$100,"<="&C2:
This portion is saying "Count the number of dates LESS THAN OR EQUAL TO C2" - Therefore, how many dates do we have that are less than or equal to the date in this current row.
So, if you put them both together, you get:
1) Only count a value with the item number is the same as this current row
2) And, of those, how many rows contain a date that is less than or equal to the date contained in the current row.
That, in effect, gives you a version number for every row.
Hope that does it.
Try this in your cell D2: (you may need to make the ranges bigger):=1+SUMPRODUCT(($A$2:$A$18=A2)*($C$2:$C$18>C2))
So I have 2 excel sheets where one excel sheet (say Sheet 1) contains some values and dates corresponding to those values. Header row contains the date and rows 2 to 6 contain the values. The other sheet (say Sheet 2) contains the list of all values that were entered in rows 2 to 6 of Sheet 1.
Sheet 1 usually gets updated in such a way that new records are added per column. For example, Sheet 1 has 3 new records, so columns B, C, and D are filled. I then want to retrieve the last occurrence of a certain value from Sheet 1 and record that last occurrence in Column B of Sheet 2. The last occurrence of that value occurs in, say cell D5 of Sheet 1, and I want to return the content of cell D1 in Sheet 2. If that value occurs again in cell F3 after another update, for example, cell F1 will be returned. A sample image is shown below, with the contents of Sheet 2 merged under the contents of Sheet 1.
Sample problem
What could be a possible formula for this? I have been trying to find possible formulas but all those solutions involve only one column or row as scope and not the whole sheet.
So far, what I'm only able to do is to return the index of the last occurrence of a certain value in just one column. See photo below.
Index of last occurrence of value sample
Thanks in advance for the help!
The images you added show two different situations: the first one (Sample problem) has the dates on the first row and the second one (Index of last occurrence of value sample) has the dates on the first column. Still, I believe that the solution I'm proposing will work in both scenarios.
If you already figured how to get the column / line number, you can use the INDEX function to return the value at the first line / column.
For image #1:
= INDEX (1:1; 1; <your formula here>)
For image #2:
= INDEX (A:A; <your formula here>; 1)
I am using the following formula:
=VLOOKUP(E9, 'Raw data'!$A$1:$I$45857, 9, FALSE)
I have two tabs and I want one column in my first sheet to lookup the # value found in 'raw data' associated with the ID number found in column E (data begins on cell E9). my second tab, 'raw data', includes that same field as found starting on E9 in sheet 1 within the data range A1:I45857. The column I want returned from 'raw data' is the 9th column. I want to be exact matches only.
What I think excel is thinking - look for e9 in the array 'raw data' and when I see it, return the value that I find in the 9th column of that row within array 'raw data'.
What excel is saying - A value is not available to the formula or function
I am confused because the value is in fact available within that array. when I filter and search for just one of the IDs, I find it in both sheets. The data type is number for both columns and there are no rogue spaces or anything...
My goal is ultimately to take a subset of ids and look at the difference between the # found on sheet1 and the number found on 'raw data'. I am Vlookup-ing so that i can grab the # value on 'raw data, set it right next to the # i am comparing it to on sheet1 and then I can pivot the data to aggregate both of those numbers based on ID and create a calculated field showing the % difference between the two.
Any input on how to fix my vlookup or a workaround to join my # from 'raw data' to sheet1 based on a common ID is MUCH appreciated.
I recommend that you look into the combination of INDEX & MATCH, rather than VLOOKUP, for situations like this. VLOOKUP has 2 main flaws: (1) you have to order your data so that your search term is the left-most column of a continuous data block [as you have just seen]; and (2) it is volatile, meaning that when a column is inserted within your data block, it will no longer properly 'count' the number of columns to move to retrieve your data.
MATCH is like half of VLOOKUP. You give MATCH a specific column or row, and a value to search for, and it will simply return the number of cells in it had to move to find that value.
=MATCH(A1,B:B,0)
This says 'look at B:B, and tell me what row the value of A1 appears on'.
INDEX is like the other half of VLOOKUP. You give INDEX a group of cells (either a row, column, or a 2D range), and a specific row number (plus potentially a column number), and it will return the value for that cell.
=INDEX(C:C,5)
This gives you the value of cell C5, which is the 5th row found in the column given to INDEX. Combine these two formulas and it will return the value of column C, where column B matches A1:
=INDEX(C:C,MATCH(A1,B:B,0))
This formula gives an identical result to
=VLOOKUP(A1,B:C,0)
VLOOKUP looks simpler here, but INDEX & MATCH is much more versatile - in your case, you wouldn't have needed to reorder your data to get it to work, you could have used the formula:
=INDEX('Raw Data'!I:I,MATCH(E9,'Raw Data'!E:E,0))
Once you get into the habit of using INDEX / MATCH over vlookup, you will find that your data is a lot more flexible to manage.
Got it to work by making my ID field in 'raw data' the leftmost column.
You don't need to start the Vlookup in column A. If the ID column is not in column A, Vlookup can still work, as long as the ID column is to the left of the column you want to return. So, if you want to return the value from column I, and the ID column is in column F, you can leave the table as it is and change the Vlookup to
=VLOOKUP(E9, 'Raw data'!$F$1:$I$45857, 4, FALSE)
This will look for the match in column F and returns the value from the fourth column, which is column I.
I have this data table and i want another result table. when I write name of state ,result table can show all of company with data1,data2 and data3.I trying use vlookup but because there are merged cells the formula just show first row.
how can I fix problem?
If I'm understanding correctly, you want to set up a lookup range so that when you enter a particular state, you can see the data for all the companies that have data in that state. Here is one way to do that.
The first thing you would need to do is set up three columns to the left of the original table:
The first column holds the name of the state associated with each row of data
The second is an index that counts off the number of data rows in each state
The third combines the first two columns to produce a unique key value for each row in the table.
All the values in these three columns can be assigned by formula. The picture below shows the formulas for the first row of cells A9:C9, which are then copied down through row 27.
The next step is to lay out the new table, which is in cells Q8:U27 in my example.
There are several thing to note about the setup. First, the state that will be displayed is entered in cell Q9, which I've highlighted in yellow. To the left of the table, in column P, I've entered item numbers from 1 to 19, which will be needed to construct the key values for the lookups. The lookup formulas themselves are in cells R9:U27; in the picture, the formulas for the first row (R9:U9) are shown (they are then copied down through row 27).
It's worth taking a moment to look more closely at one of the lookups. Here is the formula for the first company name in cell `R9'.
=IFERROR(VLOOKUP($Q$9&$P9,$C$9:$N$27,4,0),"")
Looking at each of the arguments of the VLOOKUP in turn, $Q$9&$P9 concatenates the state name in cell Q9 with the item number (1 in this case), yielding the lookup value 'California1'. The lookup table is defined as the range $C$9:$N$27 - column C of that range is what the lookup value is matched against. The third argument is the column from which to return a value if the lookup is a match. The number 4 here corresponds with the company name column of the original table. Finally, the last argument is 0 (or equivalently, FALSE) indicating an exact match is required.
Finally, the VLOOKUP function is wrapped inside IFERROR. This catches the #N/A that would otherwise be returned when no match is found, replacing it with an empty string ("").