Excel formula: How to refer a cell by its column name - excel

How can I change my excel formula if I need to replace direct reference to the cell by the column name of this cell? For example, instead of
SUM(A1:B1)
I want to use something like
SUM({Column1}:{Column2})
I know about structured reference, but I can not convert my excel dataset into named table.
Do I have any options?

This answer assumes that the column name is the content of the header row for that column.
Say we have data like:
and we want to sum part of the row based on certain months, say between Feb and Jun. In B6 enter Feb and in C6 enter Jun and in D6 enter:
=SUM(INDEX(A2:L2,MATCH(B6,A1:L1,0)):INDEX(A2:L2,MATCH(C6,A1:L1,0)))
So by changing B6 and C6 we can change the part of the second row we are summing.
EDIT#1:
If we re-arrange the headers, the formula should adapt to the re-arrangement
The formula I posted was plain-vanilla. It should work on old versions of Excel as well as the current version. I am using the US Locale. You may need to check the spelling of functions and may need to use a ; rather than a , as the field separator character.

Related

Finding partial matches within an if statement

Does anyone know how I can write an if statement that searches for partials in VBA? For example, if A2 and A3 both contain Jon, I would like the totals under the 2020 column to be summed, and then it would move down and check the values in A4 and A5. It should work the same way for Mary. But with ben, it should only total A6 because the cell underneath contains Chip. Then it should go down again and check the following two cells for a match. This is for a report that changes weekly, so the names will not always be the same. Any help is appreciated. Thank you.
As Rno said, name uniques would become an issue, but for this small data set you can add another column of name values in column F and do a sumif formula on those separated names.
See Formulas Used Pic
In cell f2 =TRIM(RIGHT(A2,LEN(A2)-FIND("-",A2,1)))
In cell H2 =SUMIF($F:$F,$G2,B:B)

Insert a formula from another sheet based on same cell values

I have a master workbook with two columns: names and formulas, which are specific for certain names. Generally, there are some 300 different names and 10 different formulas. What I need is to insert that formula in another sheet when some of this names appear - some kind of vlookup formula which won't give me value but formula.
And second part of a problem is how to make this formula (if it can be somehow inserted) dynamic and use relative values for calculation from same row in calculation sheet....
Please see my simulation below. My formula is F3 (ignored = sign) and its name is Name1. For test purpose, I typed 7 into cell F3 and 8 into cell F4.
With the formula below I typed in sheet2, I am able to call the formula of =F3 and change the reference given to cell F3 to F4 and reach to result of 8 in master sheet.
=INDIRECT("Master!"&SUBSTITUTE(VLOOKUP("Name1",Master!$I$3:$J$10,2,FALSE),"3","4"))
Maybe you can solve your puzzle by using functions I used in above simulation (INDIRECT and SUBSTITUTE).

Linking entered dates to column location

I have a spreadsheet with the following format. I was given this spreadsheet to use so I'm not sure what use these formulas for dates have in opposition to normal text.
Along the first 4 rows of each column:
K2: 2017 [=TEXT(K$5,"yyyy")]
K3: April[=TEXT(K$5,"mmmm")]
K4: Wed [=TEXT(K$5,"ddd")]
K5: 05 [=J5+1]
In another sheet, I want to do:
=Sum(K6:N6)
=Sum(K7:N7)
At the start of every week I have to change the columns to the dates of that week
=Sum(O6:S6)
=Sum(O7:S7)
Instead of manually entering the range of columns each week for the 40 rows that I have, Is there a way I can type in the date, or the column in a separate cell and use that as the object of the formula so I only have to enter a start column and end column/or date and the list will all update?
Not sure about the whole picture, but the answer to your question is yes, you can have a special cell (or several cells) where you can keep some parameters.
In order to use the value from such cell in a formula you have to specify it with the "$" characters, this way the address of the cell will not change when you copy/move the formulas around.
So, say, you want the parameter to be in cell A2 - in the formulas you have to use "$A$2".
Another way is to use named ranges. You can assign a name to a cell or range of cells. THe simplest way to do so is to select the cell you want to hold the parameter (let's say it's A2 again) and then click into the box leftmost to the formula bar (where A2 is displayed) and type there a name you'd like to use, for example "STARTDATE" and press Enter. You have just named your cell. Now in a formula you can use STARTDATE instead of cell address, which is even better, because you can use a meaningful name and the formulas will be easier to understand.

Find cells less than todays date VBA

I am trying to create a form which will find any cell with a date value less than todays date within a single column and return the row number. I am trying to use the Match function but only receive errors.
Anybody have any idea where to start with this?
Cheers
James
Ok.
Yes this can be done differently by using VBA, but if you don't know VBA it will be hard. You might be able to use excel formulas like this and this may give you what you need.
If you dates are in column A and start in A1.
Add this formula to B2 and copy it down into the other cells in the column.
=IF(A1<TODAY(),ROW(A1),"After")
This is a starting point.
I don't know what you are using the form for. eg what if many dates are before today, do you just take the first one?
ie
Add this to C1
=IF(B1<>"After",1,0)
Add this to C2 and copy down
=IF(B2<>"After",C1+1,C1)
Add this to D1
=IF(C1<>0,A1,"")
Add this to D2 and copy down
=IF(AND(C2<>0,C1=0),A2,"")
Add this to cell E1
=SUM(D:D)
Chnage column D and E to have date format.
Cell E1 now gives you the first date in the list less than today.
Harvey

Excel -Using a lower ranked value to display associated cell

i am using excel 2013. From below, e.g. if C2 is ranked 2nd, E2 value takes the value of 1st rank,i.e. 0.008. if C6 is ranked 6th, E6 takes the value of 5th rank, i.e. 0.8.
my question is how to write the formula for E2 to E7? i guess we need array formula? formula is much prefered over vba.
thanks
Try this formula in E2 copied down
=IFERROR(SMALL(D$2:D$7,C2-1),0)
If you want you can do without the ranking column, e.g. based on column D alone, you can use this version
=IFERROR(SMALL(D$2:D$7,RANK(D2,D$2:D$7,1)-1),0)

Resources