I have a transposed dynamic n x 2 array that is used to populate a combobox. The primary column alone is not descriptive enough to identify rows uniquely. I would like to use the row index to identify the untransposed column uniquely. Using both columns in the array could also be used for this but may prove problematic down the line. This question is closely related to this question.
I have used Me.cbo.ListIndex = 0 to retrieve the index value. Ideally, I'd like to assign the index of the row chosen in the combobox to a variable. The ultimate goal is to use the index in two ways:
For finding the correct column to use in future calculations
As a method for comparison against another combobox that uses the same array in order to ensure that the same row has not been chosen in both comboboxes
To visually illustrate the above, the original data looks like this:
a b c b
1 2 3 4
A B C B
The transposed array looks like this:
A 1
B 2
C 3
B 4
I would like to be able to make a distinction between selecting B2 and B4, ideally by preserving and comparing index 1 and 3 respectively (0-based).
ListIndex is from the documentation. There is no documentation that I could find about retrieving the index from the name except where the value in the selection is unique. Any Help is greatly appreciated
Related
Sorry for this question, but I haven’t found the answer in any of the texts or sites I’ve been researching. I am trying to do something that seems like it should be easy, but I don’t understand enough about arrays to pull it off. I am trying to create an array that is some number of rows; let’s say 10 rows, by 3 columns, or Myarr(1 to 10 , 1 to 3) – and then populate it as follows in memory before pasting it back into an excel sheet. Here’s an example using very simple constants and functions, not the ones I really need to run.
The reason is that I've found that running my particular construct as set of Excel formulas and VBA custom functions is very slow and results in a recalculation problem that I have written about in this forum that is not yet solved, so I am trying a work-around that performs all operations in an array, and then just pastes the result back to Excel.
Column 1 is just the list of numbers 1 to 10
Column 2 is the value of the previous row of Column 2 plus a constant; “Constant”; this is the part I really am puzzled by
Column 3 is just a function of the value of this row of Column 2
For example:
Constant = 2
Function of Column 2 value is simply Column 2 value x 4
So the output should be
Value col 1, previous value col 2 + Constant, column 2 x 4 as follows:
1,2,8
2,4,16
3,6,24
4,8,32
5,10,40
6,12,48
7,14,56
8,16,64
9,18,72
10,20,80
I just cant find any instructions about how to refer backwards to previous row values in an array and use them to produce a new value for that same column,
The simplest example would be a 1 dimensional array making a list of numbers where you started with a number and each successive row was the previous value + 1.
I realize this is probably basic stuff, but I must be searching on the wrong term to find an answer so I turn to you. Thank you very much for your help.
Did you try something like
Myarr(i,2)=Myarr(i-1,2)+const
trying to do a formula only calculator and trying to avoid a bunch of nested ifs in "hidden" columns.
Basically this is a calculator for COC type of game.
So here is a rough table (not sure how to best make a table here):
A B K M
1 name current level Max Level Next level cost
6 Soldier 2 4 X
where x=IF($K6=B6,0,VLOOKUP($A6,Masterdata!$A$4:$CD$50,32+B6,0)))
the masterdata sheet is just the name some data across several columns, some more data across several columns, and then individual columns that contain a cost starting on column 32.
this works to find the cost of the next level (3) but I would like to do a sum with something like: IF($K6=B6,0,sum(VLOOKUP($A6,Masterdata!$A$4:$CD$50,{32+B6, 33+B6,34+b6},0)))). I can get the array to work if I put in fixed numbers ie, {35, 36, 37} but not {32+B6, 33+B6,34+b6}. Additionally, the array won't dynamically change. such as current level=1, max level=9 will require a larger array than current level =5 max, max level=9. Is there a way of doing this?
Further explanation of 2nd part:
example:
current level =1 max level =9
the formula would be something like: IF($K6=B6,0,sum(VLOOKUP($A6,Masterdata!$A$4:$CD$50,{32,33,34,35,36,37,38,39},0)))) I would require 8 columns in the array to be added.
But if current level is 6 and max level is 9 then it would look something like this:IF($K6=B6,0,sum(VLOOKUP($A6,Masterdata!$A$4:$CD$50,{37,38,39},0))))
I would only require 3 columns returned in the array to be added.
So even if the formula needs to remain IF($K6=B6,0,sum(VLOOKUP($A6,Masterdata!$A$4:$CD$50,{32,33,34,35,36,37,38,39},0)))) I would like to constrain the results to only columns 37,38,39
You should exclude the cell reference from the array of constants. And you will require SUMPRODUCT (or else SUM with CSE) to coerce an array of returns:
=IF($K6=B6,0,SUMPRODUCT(VLOOKUP($A6,Masterdata!$A$4:$CD$50,{32,33,34}+B6,0)))
I'm afraid I don't understand your second query re "the array won't dynamically change".
Regards
So I abandoned the vlookup and went the index match route:
Came up with: =SUM(INDEX(Masterdata!$A$1:$Z$32,MATCH($A26,Masterdata!$A$1:$A$32,0),B26+1+14):INDEX(Masterdata!$A$1:$Z$32,MATCH($A26,Masterdata!$A$1:$A$32,0),E26+14))
Seems to work great.
Basically I am finding the row number that matches my search criteria:MATCH($A26,Masterdata!$A$1:$A$32,0) = 26
I then enter that into an index with an offset of my first column based off my min value:index(range,26,B26+1+14), along with the max value:index(range,26,E26+14) and then sum them together sum(index1:index2)
I'd like to create a table lookup formula that matches two columns. For instance, suppose I'd like to find the value of the Letter column at the row where the Type column is Biennial and the Result column is Warning.
A B C
1 Letter Type Result
2 A Annual Exceeds
3 B Biennial Warning
4 C Biennial DevelopmentNeeded
5 D Biennial PartiallyMeets
6 E Annual Meets
What would the formula look like to accomplish this?
The SUMPRODUCT() formula is really apt for situations where you want to lookup a value with multiple criteria. It is most convenient when wanting to look up numeric values, but it can be adjusted to look up string values as well. As a bonus, you can avoid having to use array formulas.
This particular problem can be tackled with the following formula (indentation added for legibility, which you can do in Excel formulas using ALT + ENTER):
=INDEX(
$A$2:$A$6,
SUMPRODUCT(
($B$2:$B$6 = "Biennial") *
($C$2:$C$6 = "Warning") *
ROW($A$2:$A$6)
) - 1
)
First, SUMPRODUCT() is used to filter out the proper rows using ($B$2:$B$6 = "Biennial") and ($C$2:$C$6 = "Warning"); the multiplication operator * functions as an AND operator (the + operator would function as an OR operator).
Then the result is multiplied by ROW($A$2:$A$6) to find the particular row that has the combination. SUMPRODUCT() then adds everything up, which in this case gives us 3. As the result sought is actually on row 2 due to the column headings, we subtract 1. By applying the INDEX() function, we get the desired result: B.
Beware though that this is the case if and only if the combination sought is unique. If the combination sought exists more than once, this will break down.
Another method that avoids array entry is:
=INDEX($A$2:$A$6,MATCH(2,index(1/(($B$2:$B$6="Biennial")*($C$2:$C$6="Warning")),0)))
It exploits the fact that the match function ignores certain errors and that index manages arrays naturally.
You can use an array formula if you like:
=INDEX($A$2:$A$6,MATCH(1,($B$2:$B$6="Biennial")*($C$2:$C$6="Warning"),0))
Enter in with Ctrl+Shift+Enter
If you want to do this without array formulas, one way you could do it is by creating a helper column.
Column D to have the formula:
=B2&C2
Copied down
Then the new formula could be:
=INDEX($A$2:$A$6,MATCH("BiennialWarning",$D$2:$D$6,0))
It's just a play on the text, really.
I feel like this should be something you can easily do in excel, but I can't seem to figure out how to. What I would like to do is sort a matrix of values on their names, but not alphabetically or by value or anything, but by another row of names. For instance:
Headers A B C
Val1 1 2 3
Val2 4 5 6
sorted_headers C B A
And i would like the matrix to be:
Headers C B A
Val1 3 2 1
Val2 6 5 4
Based on the other row "sorted_headers", I know I could program something to do this, but it just seems like something you should be able to do without a line of VBA.
Thanks!
You could:
Add an additional row to your table which uses MATCH() to get the position of each header in your "sorted" list
Use the regular Excel sorting functionality to sort left to right on that row
When you select Sort from the ribbon or after right-clicking with the sort range selected, choose Custom Sort, select Options, and set sort to Left to right. Then set the sort rows you want to use.
I've created a large-ish matrix by doing a =pearson( analysis on survey responses in google docs/spreadsheets and would like to convert it into a sorted list.
The matrix has labels (the survey questions) in row 2 and column b. Each intersecting cell has the value. Here's what the formula looks like.
=pearson(FILTER( Pc!$C$2:$AW$999 ; Pc!$C$2:$AW$2= C$2 ),FILTER(Pc!$C$2:$AW$999 ;Pc!$C$2:$AW$2=$B3))
This is what I'd like to get to:
a b c
Question one question 2 correlation
Then sorting by column c is easy.
How can I get all the points out of the matrix/array, along with the labels in this way?
Ideally I'd be able to do this only to points below the diagonal as there of course are dupes above..
Thanks!
I think I found a solution to placing the combination of the headers in a single column.
It involves a series of auxiliary columns, but works.
Let's say we have a single column with all unique headers on column A. I'll assume it's 6 values. So, on cell B1 we paste:
=ArrayFormula(join(";";A1&","&A2:A$6))
And then copy it down to B5. On C1 we join it all and split making a single column:
=transpose(split(join(";";B1:B5);";"))
If needed, we can split the combination in two columns again on D1
=ArrayFormula(split(C1:C15;","))
I don't know why, but the value on E1 does not work correctly, so I just pasted =A2
With these columns you can easily do your nice Pearson-Filter trick again to have it all in a single column. Hope this helps :)
Maybe something like this will help:
=ArrayFormula(transpose(split(CONCATENATE(transpose(C2:AW999)&char(9)), char(9))))
(C2:AW999 is your data range)