So I'm not a fan of VBA and I recently learned that OFFSET can be used with COUNTA to flashfill a range as far at it is as long as you aim for a longer range than you have data. Now I want to be able to achieve this both for columns and rows at the same time, where the rows are averaged. Could this be done? I am banging my head against the wall to find some logic to do it, but can only manage to combine it in a way that multiplies the rows with the number of the column.. which is not desired, of course.
I have posted a Minimal Reproducible Example in Excel Online:
https://onedrive.live.com/view.aspx?resid=63EC0594BD919535!1491&ithint=file%2cxlsx&authkey=!ALmV0VtFb7QZCvI
If you see Cell J9 and J11 you will see what I want to combine. The three rows in J11 and down, I want to average in J10, and spill/flashfill (like J9 and 11 does automatically because of the formula already) them from to the right, for as many columns as there data in the range A1-G4..
So I have raw data of numbers with titles in A1-G4, and by writing =OFFSET($A$1:$A$1,0,0,1,COUNTA($A$1:$EV$1)-1) in J9 I get all the titles of the columns filled from left to right, and by writing =OFFSET($A$1,1,0,COUNTA($A:$A)-1) in J11 I get the rows of the first column filled from top to bottom. They can also be combined, by writing OFFSET(Days,1,0,COUNTA($A:$A)-1,COUNTA(Days)), where "Days" is =OFFSET($A$1:$A$1,0,0,1,COUNTA($A$1:$EV$1)-1) (in a named range for readability) or OFFSET($A$1:$A$1,0,0,1,COUNTA($A$1:$EV$1)-1) without using a named range
As a thought, though I'm not sure how to implement it, maybe this could somehow be used in some form to get the column reference for the horizontal part in combination with =AVERAGE(OFFSET($A$1,1,0,COUNTA($A:$A)-1))
=MID(ADDRESS(ROW(),COLUMN()),2,SEARCH("$",ADDRESS(ROW(),COLUMN()),2)-2)
..found at https://superuser.com/questions/1259506/formula-to-return-just-the-column-letter-in-excel/1259507
Now, based on your explanation, here is the screenshot of my test:
Section A1:Exxx
I have converted that section into a Table, called «TblData», having numerous avantages:
It expands automatically without any additional efforts/formula
We can identify Data by its Columns attributed automatically by the Table [#1], [#2],[#3], [#4], [#5]
Section J9:N9
As a replica of the table name, I have used the following formula to retrieve it:
=INDEX(TblData[#Headers],1,COLUMN(A1)) '<--- This is for J9
=INDEX(TblData[#Headers],1,COLUMN(E1)) '<--- This is for N9
Section J11:Nxx
As a replica of the Table Content, I have used the following formula to populate the content:
=INDEX(TblData,ROW($A1),MATCH(J$9,TblData[#Headers],0)) '<--- This is on J11
=INDEX(TblData,ROW($A3),MATCH(N$9,TblData[#Headers],0)) '<--- This is on N13
Section J10:N10
Now this is the interesting part of the Average, so here is the formula I used for it:
=AVERAGE(TblData[1]) '<--- This is on J10
=AVERAGE(TblData[5]) '<--- This is on N10
NB: (1) Instead of using the Content below J10:N10, I prefer to reuse the Table as it expands automatically as more rows are added.
(2) Unless it is really necessary, I feel it is a double work as well to replicate again A1:Exxx from J9:Nxxx, because you can use the Table for whatever you need, with less maintenance.
Kindly find attached the file as well after I updated those items:
File Link: https://drive.google.com/open?id=1wRbpUxg0XLpfGqdvMF4fNKXDrL7xPPWs
We can correspond more below for further info. Hoping you to strech more your compentence :)
Sorry, mate, I can't figure out what you want to calculate. If it makes sense to add J9+J11 then you could just concatenate the two formulas in J9 and J11 with a plus sign. After much deliberation I decided to assume that your question is not one of formula but of formula-writing - "referencing" for short. Therefore I prepared this answer for you, hoping that it will prove helpful.
Building on your named range Days I suggest you create a dynamic named range Data with this formula.
[Data] =OFFSET(Sheet1!$A$1,0,0,COUNTA(Sheet1!$A:$A),COUNTA(Sheet1!$1:$1))
The range thus defined is dynamic in both directions. However, bearing in mind that OFFSET is volatile (slows down your worksheet) you may like to keep its use limited to this one formula and perhaps start the range at A2, but I shall tempt you to break the rule. Now you can use the INDEX function to refer to the Data range.
= INDEX(Data, [Row number], [Column number])
defines a single cell. But by setting either column or row to zero you can define an entire column or row. =INDEX(Data,0,1) defines column 1 of the Data range, =INDEX(Data,1,0) defines its first row.
=INDEX(OFFSET(Data,1,0),0,1) defines the first column of a range moved down by one row from its original position. I recommend the alternative and start the Data range from A2 and perhaps declare another range for the first row if needed.
=AVERAGE(INDEX(Data,0,1)) would draw the same average you already have in your sheet, provided that Data was defined starting at A2. For fun's sake, =AVERAGE(INDEX(OFFSET(Data,1,0),0,1)) would do the same without the change in the range's definition.
=COLUMN() returns the number of the column this formula resides in. So, you could enter =COLUMN()-6 in column G, copy to the right and get a count starting from 1. (You can do the same vertically with the ROW() function.) Applied to your formula, =AVERAGE(INDEX(Data,0,COLUMN()-6)) would return the average from column 1 if entered in column G, and from columns 2, 3 4, etc as copied to the right.
As I said, I don't understand enough of your request to bring this idea to a conclusion but I think that using the method described above will provide you with a tool to copy formulas into the table your sample has at its right. If you would elaborate on your requirement I might be able to assist more.
My apologies in advance - this is my first question on Excel here on SE, and I am fairly new at using it (if this question should be migrated to SuperUser please let me know in comments).
I have a spreadsheet which looks like this:
I need to combine the duplicate properties, summing the rows as I go.
Thus, the outcome should look something like this:
Notice that in this example I have created a third column for the duplicate properties - this is fine, though ideally, the original columns would be hidden after the duplicate columns are summed up. I have also created another column for property 2, even though it does not have a duplicate - this is also fine, though leaving property 2 alone entirely would also be acceptable.
I have read this question, but my question is somewhat different in that I am trying to sum the values, as well as attempting to sum based on duplicate columns, and not duplicate rows. I have also attempted to manipulate the instructions from here and here, though am having little luck.
Any help would be greatly appreciated!
With this data
Add this formula starting from B6 to E6 with CTRL+SHIFT+ENTER
=IFERROR(INDEX($B$1:$J$1, MATCH(0,COUNTIF($A$6:A6, $B$1:$J$1), 0)),"")
And this formula starting from B7 to E8
=SUMIF($B$1:$G$1,B$6,$B2:$G2)
I want to get a sum of the cells in column B with 2 criteria (Which type [WIND or WATER], and it's location [e.g VIC = 1-7, NSW = 15-17])So i would hope that cell F4 becomes 78 and G4 becomes 14.
Additional notes: I am pasting in the raw data and the rows are not always set.
Example:
Can anyone please help?
for F4 use the following
=SUMIFS($B$2:$B$9,$A$2:$A$9,">=1",$A$2:$A$9,"<=7")
For G4 use the following:
=SUMIFS($B$15:$B$22,$A$15:$A$22,">=1",$A$15:$A$22,"<=7")
for single entry ranges like F16 use the following
=SUMIF($A$2:$A$9,20,$B$2:$B$9)
and G16 uses:
=SUMIF($A$15:$A$22,20,$B$15:$B$22)
There are other possible solutions depending on how complex you want to make the formula. You can also make your life a little easier if you set your upper and lower limiting boundaries for a region in their own separate cells without the excess text.
I need to reduce a file I am developing and I know one good way is using VBA. Unfortunately I am not advanced in VBA yet and I am struggling in designing this.
I have a list price organized in three different streams, and I want to combine in one like below:
Stream Site Brand Code Price
Mainstream Boston Brand 01 Formula
Midstream New York Brand 02
Midstream Los Angeles Brand 02
Currently I am using a formula that basically does the following:
=IF(AND(stream="mainstream",Site = "Boston"),vlookup(Brandcode,list 1, 2,0),IF(ANd(stream="midstream", Site = "Boston", vlookup(Brandcode,list 2, 2,0),...))
The formula actually works just fine, the problem is I am testing many other conditions than just this one and thus the file is becoming very heavy, so I wanted to create a VBA code to create either a function or a subroutine, but I am struggling to understand how to do it.
Thanks
This can actually be achieved without using VBA by using named ranges instead. Looking at the formula, it's clear that your lookup range varies based on the combination of stream and site.
You can create a Named Range for each of these lookup ranges. To do so, highlight the range of cells that contains the first lookup group (let's say Midstream New York). Next, press CTRL + F3 to open up the Name Manager. Finally, give this group the name MidstreamNewYork. (Note: you cannot include spaces in the name).
Next, you can update your Vlookup function. You no longer have to include the IF(AND... component because your lookups will be dynamic. Let's say you're inputting a formula on Row 2, the formula would be:
=VLOOKUP(C2,INDIRECT(SUBSTITUTE(A2&B2, " ", "")),2,FALSE)
Let's break down the formula. (1) C2 is just the brandcode (I assumed it was in column C.(2) TheINDIRECTfunction treats aStringas aRange. We are passing in CellsA2andB2, which are "Midstream" and "New York", respectively. We use theSUBSTITUTEfunction to remove the spaces since they aren't allowed. So now, we are looking up a named range calledMidstreamNewYork` (sound familiar?). (3) The rest of the VLOOKUP is standard: lookup the second column, and only match exacts.
Give it a try and let me know if it meets your requirements.
I’m currently looking for two formulas in order to gain in efficiency. Let me develop my research.
Firstly I’m looking for a “sum composition finder”. Basically let imagine I have 5 figures and a sixth which is the sum of x of those figures.
I’m looking for a formula which could find what the figures that compose my sum are.
Here’s an example:
1) 54
2) 21
3) 20
4) 47
5) 62
Sum : 41
Here I’ve got a sum of 41 thus I want the formula to be able to find 21 and 20 which make 41. Does someone have any idea about how I could make this works ?
Secondly I’m looking for a dynamic vlookup. As you may know vlookup use an index number to take the value needed. My plan is to make a vlookup based on the name of the column thus if there is any change in the table (I.e if I’m adding a column on my table) my vlookup isn’t broken. Also I want to know if it is possible to fix a dynamic table area.
For instance if my table goes from column A to E I would like that my vlookup is able to extend to F when I’ll add a column by himself.
I hope I’ve been clear enough, feel free to ask for some more information if something isn’t clear.
Thank in advance !
You can choose the column to retrieve in a VLOOKUP by applying a MATCH function against the column headers.
The formula in I2 is =VLOOKUP($G2,$A$2:$Z$99,MATCH($H2,$A$1:$Z$1,0),FALSE).
Another method is using INDEX against the data grid, applying MATCH to both the row_number and column_number parameters. In the above case, this would be =INDEX($B$2:$Z$99,MATCH($G2,$A$2:$A$99,0),MATCH($H2,$B$1:$Z$1,0)). Of course, you would have to get the formulas out of the way of the expansion area in order that you do not receive circular references.
Addendum: I've modified the formulas originally supplied to demonstrate expandability.