Excel - Delimiting addresses creates formulas -don't want - excel-formula

Surely I can't be the only person who's ever have this issue.
I have a dataset which includes many hundreds of addresses in unmanagable formats, but I need to be able to sort them, so [Street Name] [Street Number] is the logical format.
My current method is to delimit then concatenate large sections at a time (some situations require more attention than others, especially where multiple street names are concerned).
However, here's what happens when I delimit this range:
I tried preformatting some of the target cells to General, Text, Number, but nothing works for the whole set. Sometimes it turns it into a date, sometimes it automatically calculates division and subtraction, sometimes it does actually put it as text, but then of course I can't sort it because it's not a number.
Is there a way to avoid this from happening?
Thanks for your time.

No you aren't the only person facing this issue, and there are quite a few solutions available in the internet.
However they all turn out to be a bit complex and it's much simpler to understand if the same is done in vba. Nevertheless, it's still doable by excel-formula. So here's my take.
To get the result as below
you may use these formulas:
Cell B2: =IF(ISERROR(FIND(" ",A2)),A2,LEFT(A2,(FIND(" ",A2,1)-1)))
Cell C2: =MID(A2,LEN(B2)+2,LEN(A2)-LEN(B2)-LEN(D2)-1)
Cell D2: =IF(ISERROR(FIND(" ",A2)),A2,MID(A2,FIND("~",SUBSTITUTE(A2," ","~",LEN(A2)-LEN(SUBSTITUTE(A2," ","")))),300))
and then simply copy & paste to applicable rows below.
Note: this formula assumes the character ~ is not being used in the data set. If that isn't the case, replace that character in the formula, with the one that can't be found in the entire data set.

Related

Excel - Increment a number based on values from two other columns

I have 2 columns one is a period and another is a cycle. I need to create a 3rd column where I create a cycle identifier. Where the Letter changes on the cycle but resets every period.
I seem to have it with the following formula
IF(A1<>A2,1,IF(B1<>B2,C1+1,C1)). Which will give results of 1, 2 or 3. Then to get the numbers into letter form by using a switch SWITCH(C1,1,"A",2,"B",3,"C") in an adjacent cell. However I was curious if there is a more efficient or better way to accomplish this perhaps in all in one formula.
Any suggestions would be greatly appreciated.
Period & Cycle
Copy this formula to cell C2 and copy it down.
=IF(B2<>B1,IF(A2<>A1,CHAR(65),CHAR(CODE(C1)+1)),C1)
In Excel 365, you could use a spill formula like this:
=CHAR(B2:B15-XLOOKUP(A2:A15,A2:A15,B2:B15)+65)
You could argue that this is less efficient because it uses a lookup so there could be a speed hit with large amounts of data. On the other hand, it could be considered more efficient because it is a single formula and doesn't need to be pulled down.
If you were worried about the speed, you could set the binary search option in xlookup:
=CHAR(B2:B15-XLOOKUP(A2:A15,A2:A15,B2:B15,,2)+65)
(Column A has to be sorted ascending for this to work - I'm fairly sure that where there are duplicates this will still give the first match. However Microsoft are quoted as saying that there is only a slight benefit of using binary search according to this and other articles)
You could make the formula more dynamic:
=CHAR(B2:INDEX(B:B,COUNTA(B:B))-XLOOKUP(A2:INDEX(A:A,COUNTA(A:A)),A2:INDEX(A:A,COUNTA(A:A)),B2:INDEX(B:B,COUNTA(B:B)))+65)
Or using Let
=LET(Period,A2:INDEX(A:A,COUNTA(A:A)),
Cycle,B2:INDEX(B:B,COUNTA(B:B)),
CHAR(Cycle-XLOOKUP(Period,Period,Cycle)+65))

ADDRESS TO RANGE

I have this formula:
=MATCH(""&"W"&C2&"",'Raw Data'!$5:$5,0) --> Which extract the column number, then
=SUBSTITUTE(ADDRESS(1,E3,4),"1","") --> I convert to letter
It returns: DH
Finally, I want to use that value of "DH" into the following formula
=INDEX('Raw Data'!A:A,MATCH(E26,'Raw Data'!DH:DH,0))
I tried many times and ways without success.
Data is dynamic, so the first value I'm looking for W2 (for example) will not always be in the same column.
Depending on the variable which you get on the column number, I want the spreadsheet to select that column.
Here is a simplified demonstration of what I think you are trying to do here:
Formula in A3:
=INDEX(A11:A20,MATCH(A2,INDEX(A11:E20,,MATCH("W"&A1,5:5,0)),0))
As you see, this can be done without transformation of a column number into a letter reference. It's simply a matter of nested INDEX/MATCH functions as per #BigBen in the comments.
Please adapt the above to suit your ranges.
Few more remarks just for future reference:
ADDRESS - This is a so-called volatile function. Though maybe not obvious these type of functions recalculate on any save, open, edit on your worksheet. The more of these, the slower your workbook gets.
""&"W"&C2&"" - There is no need to concatenate empty strings in front of other string values leaving you with the exact same results but formulas that are simply harder to read.

Can these formulas be simplified? Why does INDIRECT function seem to not work inside an ISBLANK test within a MATCH formula?

Summary
I need an array formula that takes a row of data of certain length from Sheet1. For that row, in each column that is not blank, I need to grab the Sheet1 header value for that column and display that data in a continuous row on Sheet2 (without any spaces in between the row's cells).
Background
I have a table of data (employees and industry certifications with expiration date being the table's cell data) on sheet 1, with a row for each employee the spreadsheet is tracking. The certifications are the columns.
We are using this information to link to ID Badge Printer software (Bodno Silver), where we are limited to linking columns of data to a particular textbox.
The problem lies in the fact that not everyone has every certification. The rows are peppered with blanks separating the certifications that each employee does have. While setting up the required text boxes in the badge software template, that each link to a specific column, I quickly realized that since not everyone has every certification if we used the data how it was we would have a bunch of strange looking blanks in between the listed certifications rather than a continuous list.
What I did
My solution to this (which I'm open to a better one if anyone knows of one, other than "use better software"), was to create a new sheet and array formulas that no one would use except for me and the id printer software. This sheet would have a similar data table that took the rows of data interspersed with blank cells between expiration dates, and put the matching column headers for cells that had a date in them into a continuous row of the same maximum length (eliminating the blank cells).
Essentially, this would allow me to circumvent the restrictions of the badge software and each textbox would be MatchedCert1, MatchedCert2, MatchedCert3, etc. up to the original maximum number of certifications.
Pictures are probably better than my words at explaining what I am going for:
Sheet1 (source)
Sheet2 (result)
The array formulas
I worked on this one for a while. What I thought would be a simple INDEX, MATCH, ISBLANK formula (that I could create using the appropriate relative and absolute cell linking) and then expand to the whole sheet turned into a witch hunt and me praying for forgiveness for my sins to all that may be holy. Also a lot of googling.... I realized quickly that this one may not be so simple after all.
Finally, I arrived at the following two array formulas in order to correctly show what I was going for:
First Column of training section
{=IFERROR(INDEX(Sheet1!$E$2:$P3,1,MATCH(FALSE,ISBLANK(Sheet1!E3:Q3),0)),"")}
(easy enough, right? I thought so...)
I felt good about this until I tried to think through what would be required to get the formula to be universal so that I could use it on the entire table.
I feel dirty just putting the following in public, but here goes...
Second column through last column array formula
{=IFNA(INDEX(INDIRECT(ADDRESS(ROW($E$2),(MATCH(E3,Sheet1!$2:$2,0)+1),1,1, "Sheet1")&":"&ADDRESS(ROW(E3),COLUMN($Q3),1)),1,MATCH(FALSE, ISBLANK(INDEX(INDIRECT("Sheet1!"&ADDRESS(ROW(E3),(MATCH(E3,Sheet1!$2:$2,0)+1),1)&":"&ADDRESS(ROW(E3),COLUMN($Q3),1)),0,0)), 0)),"")}
(please don't call the police...)
[ninja edit] While this array formula works for 2nd result column through the final column, it doesn't work if there's not a blank column following the result range. The actual spreadsheet has 4 different groups of certifications that run horizontally, but I was able to just add a blank column in the corresponding data from the other sheet easily enough, so I just let it go. I'd give somebody a nickle for the answer to why that's the case here too [/edit]
Results
The first array formula, and INDEX MATCH using ISBLANK is rather straightforward.
The biggest question for me here, and the thing that drove me absolutely nuts for a couple of days, is why the second array formula requires the additional INDEX function nested inside of the ISBLANK function.
While taking the function apart and experimenting I realized that if I have any INDIRECT reference inside a ISBLANK function, which is itself inside of a MATCH function, the result of the match was ALWAYS 1:
{=MATCH(FALSE,ISBLANK(INDIRECT("$E3:$Q3")), 0)}
The above ALWAYS returns 1, whereas if I put the range in explicitly, the function would work just fine. That wasn't an option for me, since I needed to dynamically return the starting position for the match using the previous cell's address.
However, adding an INDEX function (with a column and row value of 0) to encapsulate the INDIRECT function provides the correct answer. I figured this out just by trial and error.
Questions
Can someone with more knowledge please let me know what is causing this behavior?
As a broader question, given I am limited to using formulas (no VBA), I would also like to know if I'm going about this in the wrong way or if there is a much simpler way of accomplishing this without this behemoth of a formula?
I know this sheet will probably require maintenance in a year - good luck future self!
Put this in E3, Copy over and down
=IFERROR(INDEX(Sheet1!$2:$2,AGGREGATE(15,6,COLUMN(INDEX($E:$P,MATCH($C3,Sheet1!$C:$C,0),0))/(INDEX(Sheet1!$E:$P,MATCH($C3,Sheet1!$C:$C,0),0)<>""),COLUMN(A:A))),"")
As to why your formula is not working, it is too convoluted to parse. One note, unless the sheets is the variable, one should avoid INDIRECT as much as possible. INDEX can almost always be used in its place.
Both INDIRECT and ADDRESS are volatile functions. Volatile functions will re-calculate every time Excel re-calculates, leading to a lot of unnecessary computations.
Not a solution but to answer why you are seeing this behavior:
EDIT: PREVIOUS EXPLANATION WAS JUST PLAIN WRONG
This confused me so, I did a bit of investigation:
I think that your problem is actually coming from the ISBLANK function because it is intended to be used with single values, and cannot handle ranges. Any BLANKs which are returned by functions are only converted to numeric values (0), when the BLANK is returned to (or displayed on) the sheet. If the function is returning to another function, the BLANK value seems to be preserved.
EDIT: ADDING A SOLUTION WITHOUT ARRAY FORMULAS
This is probably more complex than using an array formula... but I strongly dislike them, so do all I can to remove them.
Firstly, I would add an index to your positions in the results sheet:
=IF(F$7>COUNTIFS($F3:$L3,"<>"),
"",
IF(
MINIFS(
$F$7:$L$7,$F$7:$L$7,
">" & IFNA(INDEX($F$7:$L$7,MATCH(E9,$F$2:$L$2,0)),0),
$F3:$L3,
"<>"
)=0,
"",
INDEX(
$F$2:$L$2,
MATCH(
MINIFS(
$F$7:$L$7,$F$7:$L$7,
">" & IFNA(INDEX($F$7:$L$7,MATCH(E9,$F$2:$L$2,0)),0),
$F3:$L3,
"<>"
),
$F$7:$L$7,
0
)
)
)
)
Basically, the formula looks at the cert in the previous cell, and looks for the next, minimum index, greater than that.

Use INDEX/MATCH to select formula written as string, and enable it?

I have a pricelist, with currently 5 different categories of products. Each product will have to have two different prices. Depedning of the product and the type of price, the calculation will be different. Therefor I've used INDEX/MATCH to find the formula needed, from a table I created.
Below a screendump, and I wanted to attach the Excel fil, but canøt seem to work out how.
Question: HOW do I then "run" the formula I fetched? -I've tried different suggestions on using EVALUATION, but it doesn't seem to cut it? Also I've tried "Indirect' on the whole formula, without success.
I would like to avoid any VBA for this case.
Can anybody provide some insight?
You could but if I understand properly, the only thing changing in the formulas is the "muliplier" number, then it's better to lookup that number instead of the whole formula. The other method (which would use Evaluate etc) is not be considered "good practice" for a number of reasons.
EDIT:
I didn't see the 2nd varying value (since I was on the SO mobile app) but it's still not an issue since it would a target column. You could be thinking of the opposite: sometimes lookups based on multiple criteria can get complicated, but this a matter of more data, as opposed to adding criteria for the lookup.
VLookup would have been the simplest method, like G2 could have been:
=VLOOKUP(E2, $J$4:$L$8, 2, False)
...to return the second column of range J4:L8 where the first column equals E2. (Then for the next required column, same formula except with 3 instead of 2.)
Since I wasn't sure more columns could be added one day, I allowed for that by, instead of specifying "Column 2 or 3" etc, it finds the column dynamically by name. (So the multiplier/factor used in G2 will change if you change the title in G1 to the name of a different column existing in the target data chart.
For the sake of neatness as well as potential of additional columns like G & H, I moved the lookup table to a separate sheet. It can stay out of the way since you won't need to see or change it very often. (If the same chart was going to be referenced by many workbooks, you could even move it to a separate workbook and point all formulas at that, since it's always best to have one copy of identical data instead of many in different workbooks.
Also to assist with potential future changes (and just to be tidier), instead of referring to the target table range addresses (like "J4:L8" etc) I named two ranges:
the table of multiplier/factor data can be referred to by it's address, or by myMultipliers
the titles of the same table is also called myMultiplierTitles (used to match to the titles of column G & H on the original sheet.
Formula
After those changes, the lookup formula in G2 is:
=INDIRECT(VLOOKUP($E2,myMultipliers,MATCH(G$1,myMultiplierTitles,0),FALSE)&ROW())*VLOOKUP($E2,myMultipliers,MATCH(G$1,myMultiplierTitles,0)+1,FALSE)
INDIRECT returns the value of a cell that you refer to by name (text/string) as opposed to directly (as a range). For example:
=INDIRECT("A1")
returns the same as
=A1
...but with INDIRECT we can get the name from elsewhere (a cell, function or formula). So if x="A1" then =INDIRECT(x) returns the same as the 2 above examples.
Your original plan of storing the entire formula in a table as text would have worked with the help of INDIRECT and/or EVALUATE but I think this way is considered better practice partly because it facilitates easier future expansion.
The formula is longer than it would have been, but that's mostly because it's dynamically reading the field names. And size doesn't matter. :-)

AVERAGEIFS does not work, but AVERAGE(IF( does

We have a large spreadsheet that we use to calculate performance for race car drivers. It has been stable for quite some time. Today, I opened it and found that one of the tables was not calculating correctly. I tried recalculating the sheet (it is set to manual calc), and tried rebuilding the tree (ctl+alt+shift+f9) to no avail. Other formulas referencing the same named range function correctly as do other formulas using average if.
Variables
list_of_names = A list of first and last names in a single text string imported from a CSV file
local_name = A name (100% guaranteed to be included in list_of_names) to calculate an average of a drivers performance in a given sector of the track
sector_percent = A percentage of a driver's trips through a particular sector that fall into a pre-determined range
sector_count = The number of trips the driver makes though a sector
My original formula returns a #Value error. This is the original formula (the actual formula contains an IFERROR statement, but I have removed it here for clarity. The #VALUE error happens either way).
{=AVERAGEIFS(sector_percent,list_of_names,local_name,sector_percent,">0",sector_count,">"&min_number_sectors)}
After some experimenting, I have found that the following formula successfully reports the correct answer:
{=AVERAGE(IF(list_of_names=local_name,IF(sector_percent>0,IF(sector_count>min_number_sectors,sector_percent,0))))}
If you strip the list_of_names and local_name variables from the AVERAGEIFS formula, it behaves correctly (given the data that meets the criteria). This led me to believe that the list of names and the local name were not of a matching data type. However the #VALUE error still occurs if both are set to general or text. TYPE(list_of_names) or TYPE(local_name) both return 2 presently. {TYPE(list_of_names)} returns 64 as it should.
The sheet is able to perform the list_of_names to local_name function correctly in other places in the workbook and in other areas of the same sheet.
I have tried:
-Replacing all named ranges with the actual cells referred to by the name in the formula
-Referring to different local_names in the list_of_names
-INDEX(list_of_names,ROW(A1)) correctly reports the list of names when you drag it out.
-Various orders of criteria, using other criteria.
-A number of other heat of the moment changes that I can't currently recall
Essentially, the list_of_names to local_name comparison fails in this area of the sheet every time using AVERAGEIFS where AVERAGE(IF( does not.
To me the formula is correct either way, but the sudden failure in this one part of the sheet is odd.
This is my first post here and I would appreciate any help that is available. Hopefully, I have provided enough information to lead to an answer. If not, let me know and I will fill in any gaps.
Both #barryhoudini and #Jeeped are correct. I had failed to drag the information in one of the source tables far enough creating a size mismatch in the range sizes. I can't figure out how to accept that as an answer other than to answer it myself, which would not apply the proper credit where it is certainly due. I thank you both for the assistance, it was concise and excellent. I still cannot understand why one formula works and one does not. Is it possible that the AVERAGE(If has a less restrictive set of constraints when it comes to range size?

Resources