Nesting error in Excel Formula - Changes to If - excel

I'm currently trying to record a macro for my excel spreadsheet, but keep recieving the message "The specified formula cannot be entered because it uses more levels of nesting than are allowed in the current file format can anyone help me out in fixing the formula to make it smaller?
=IF(ISNUMBER(SEARCH("Conductor + Surface",B3)),"Conductor + Surface",IF(OR(ISNUMBER(SEARCH("17
1/2",B3)),ISNUMBER(SEARCH("Drilling",B3)),ISNUMBER(SEARCH("12 1/4",B3)),ISNUMBER(SEARCH("8
1/2",B3)),ISNUMBER(SEARCH("Run Screens",B3)),ISNUMBER(SEARCH("Temporay",B3)),ISNUMBER(SEARCH("BOP
Hop",B3)),(ISNUMBER(SEARCH("Data Acquisition",B3)))),"Inter, Res, Lower Comp., &
TP&A",IF(ISNUMBER(SEARCH("Maintenance",B3)),"BOP Maintenance",IF(OR(ISNUMBER(SEARCH("Re-
entry",B3)),ISNUMBER(SEARCH("Wellbore Prep",B3)),ISNUMBER(SEARCH("Run
Completion",B3)),ISNUMBER(SEARCH("Install TH",B3)),ISNUMBER(SEARCH("BOP
Pull",B3)),ISNUMBER(SEARCH("Subsea Move Off",B3)),ISNUMBER(SEARCH("BOP Run -
Completion",B3))),"Upper Comp & TH",IF(ISNUMBER(SEARCH("Rig Move - N and C",B3)),"Rig Move - N and
C",IF(ISNUMBER(SEARCH("Install XMT",B3)),"Install XMT w/ Rig",IF(ISNUMBER(SEARCH("Open
Plugs",B3)),"Open Plugs",IF(ISNUMBER(SEARCH("Rig Move - S and B",B3)),"Rig Move - S and
B",IF(ISNUMBER(SEARCH("Install VXT",B3)),"Install VXT","ERROR IN EXCEL FORMULA")))))))))
Currently there is a column with tasks that are too in depth, aka "New Conductor + Surface" or "ADCO - DG2 8 1/2" I want to make a new column with shorter names for each of them depending on certain words that are in the detailed column. I would then like to return an error if there is a detailed task that is not described properly.

This can be done by modifying the setup in this link to a 2 column lookup table.
See below for sample:
Array formula is =IFERROR(INDEX(lookupList,MATCH(TRUE,ISNUMBER(SEARCH(list,D7)),0),2),"NOT FOUND")
remember to press Ctrl+Shift+Enter when exiting cell edit mode.

Related

Index Match to return MAX Date with multiple criteria

apologies for this, I'm assuming this is simple but a few hours of SO googling hasn't helped
Enough whining from me:
Consider the following dataset:
ID, Date, Review, Review Status
1 01/02/18, "Cool", Positive
1 01/03/18, "Awesome", " Positive
1 01/01/18, "Cumbersome", Negative
1 01/02/18, "Rubbish!", " Negative
I'm currently using an array type index match to get the latest review based on a few conditions
I have two columns one which says positive, one negative.
in each of the column I would like to return the latest positive review but I'm unsure how to get the max date within the below formula:
{=index(C2:C4, MATCH(1,(1 = A2:A4)*("Positive" = D2:D4)*(maxdatehere = B2:B4),0))}
The data I have is around 7k rows and is Google Review Data and pretty much matches the example above.
I'd rather not use VBA as I've never really used it before (but will do so grudgingly)
as this is excel I've not created a google demo sheet, but happy to do so for ease of the experts and for others to benfit if they find there way here one day.
If you have Office 365:
=INDEX(C2:C5, MATCH(1,(1 = A2:A5)*("Positive" = D2:D5)*(MAXIFS(B:B,A:A,1,D:D,"Positive") = B2:B5),0))
Confirme with Ctrl-Shift-enter instead of Enter when exiting edit mode.
If you have 2010 or later then:
=INDEX(C:C,AGGREGATE(15,7,ROW(C2:C5)/((A2:A5=1)*(D2:D5="Positive")*(AGGREGATE(14,7,B2:B5/((A2:A5=1)*(D2:D5="Positive")),1)=B2:B5)),1))
Entered normally.

Power Query: Adding characters to a set limit across several columns/rows

Very new to PQ, and I'm pretty sure it can do what I need in this situation, but I need help figuring out how to get there.
I have a timesheet report with 20 columns covering 50 rows that will need to be formatted to a word doc for uploading into a separate system. The original data in the cells range from 0 to any negative 2 digit number (ex: "-20"), but they need to be formatted to a seven-character set ending in ".00".
Examples:
0 will need to become "0000.00"
-4 will need to become "-004.00"
-25 will need to become "-025.00"
I think I should be able to use the text.insert function, but I'm not familiar enough with M Language to get it to do what I want it to do.
Any solutions/suggestions?
Here's my previous answer revisited...set up to use a function. You can just invoke the function once for each column you want to reformat. You'll just pass the name of the column you want to reformat to the function as you invoke the function each time.
Create a new blank query:
Open the new query in Advanced Editor and highlight everything in it:
Paste this over the highlighted text in the Advanced Editor:
let
FormatIt = (SourceColumn) =>
let
Base = Number.Round(SourceColumn,2)*.01,
Source = try Text.Start(Text.Range(
if Base < 7 then Text.From(Base) & "001" else
Text.From(Base),0,7),2) & Text.Range(Text.Range(
if Base < 7 then Text.From(Base) & "001" else
Text.From(Base),0,7),3,2) & "." & Text.End(Text.Range(
if Base < 7 then Text.From(Base) & "001" else
Text.From(Base),0,7),2)
otherwise "0000.00"
in
Source
in
FormatIt
...and click Done.
You'll see a new function has been created and listed in the Queries list on the left side of the screen.
Then go to your query with the columns you want to reformat (click on the name of your query that has the numbers you want to change in it, on the left side of the screen) and...
Click Invoke Custom Function
And fill out the pop-up like this:
- You can make up a different New column name than Custom.1.
- Function Query is the name of your query you are calling (the one you just created when you pasted the code)...for me, it's called Query1.
- Source Column is the column with the numbers you want to format.
...and click OK.
You can invoke this function once for each column. It will create a new formatted column for each.
You can use this formula = Text.PadStart(Text.From([Column1]),4,"0")&".00") in PQ to add new column that looks similar to your needs.
Here's an admittedly "busy" formula to do it:
= Table.AddColumn(#"Changed Type", "Custom", each Text.Start(Text.Range(if Number.Round([Column1],2)*.01 < 7 then Text.From(Number.Round([Column1],2)*.01) & "001" else Text.From(Number.Round([Column1],2)*.01),0,7),2) & Text.Range(Text.Range(if Number.Round([Column1],2)*.01 < 7 then Text.From(Number.Round([Column1],2)*.01) & "001" else Text.From(Number.Round([Column1],2)*.01),0,7),3,2) & "." & Text.End(Text.Range(if Number.Round([Column1],2)*.01 < 7 then Text.From(Number.Round([Column1],2)*.01) & "001" else Text.From(Number.Round([Column1],2)*.01),0,7),2))
It assumes your numbers that you want formatted are in Column1 to start. It creates a new column...Custom...with the formatted result.
To try it out, start with Column1 already populated and loaded into Power Query; then click the Add Column tab and then the Custom Column button, and populate the pop-up window like this:
...and click OK.
With more time, the repetitive parts could be made with variables to shorten this up a bit. This could also be turned into a function, given some time. But I don't have the time right now, so I figured I'd give you at least "something."

Excel concatenate fill down won't advance by 6 the way I need it to

I have an excel worksheet that has formulas and references other tabs in the workbook.
I'm pulling a street number and street name and putting it in another tab.
Here are 2 lines of formula:
=CONCATENATE('Building Limits'!C669," - ",'Building Limits'!C672," ",'Building Limits'!D672)
=CONCATENATE('Building Limits'!C675," - ",'Building Limits'!C678," ",'Building Limits'!D678)
I have tried to fill down, copy & paste special and this is what I get:
=CONCATENATE('Building Limits'!C676," - ",'Building Limits'!C679," ",'Building Limits'!D679)
I need the line below to advance to C681 and C684.
I know I can copy down and adjust each line, but I do not have to the time to do it all manually. I have to add 140 more lines to get my sheet to correctly reference the addresses that I've already entered.
I didn't create the workbook, so it's more than a little challenging.
Can anybody offer up a suggestion?
Use INDEX():
=CONCATENATE(INDEX('Building Limits'!C:C,(ROW(1:1)-1)*6 + 669)," - ",INDEX('Building Limits'!C:C,(ROW(1:1)-1)*6 + 672)," ",INDEX('Building Limits'!D:D,(ROW(1:1)-1)*6 + 672))
6 is the spacing and the + 669 and + 672 are the starting rows.

Why am I getting the error - Too many arguments from this formula?

I am trying to create a macro for the following formula. First though, I need to get the formula working when referencing a spreadsheet saved separately on the hard drive. Below is what I have but I am getting the error of Too many arguments.
=IFERROR(IF(C2<>"",IF(AND(VLOOKUP(A2&"",[LPSMatch.xlsx]Sheet1!$A:$B,2,FALSE)="Assigned Attorney",OR(B2="Jimmy Edwards",B2="Kathleen McCarthy")),"Sales Team",IF(AND(VLOOKUP(A2&"",[LPSMatch.xlsx]Sheet1!$A:$B,2,FALSE)="Intake Team, Assigned Attorney, or Sales Team",B2<>"Jimmy Edwards",B2<>"Kathleen McCarthy"),B2,IF(AND(VLOOKUP(A2&"",[LPSMatch.xlsx]Sheet1!$A:$B,2,FALSE)="Intake Team, Assigned Attorney, or Sales Team",OR(B2="Jimmy Edwards",B2="Kathleen McCarthy")),"Sales Team",IF(VLOOKUP(A2&"",[LPSMatch.xlsx]Sheet1!$A:$B,2,FALSE)="Assigned Attorney",B2,IF(AND(VLOOKUP(A2&"",[LPSMatch.xlsx]Sheet1!$A:$B,2,FALSE)="Sales Team",OR(B2="Jimmy Edwards",B2="Kathleen McCarthy")),"Sales Team",IF(C2<>"",VLOOKUP(A2&"",[LPSMatch.xlsx]Sheet1!$A:$B,2,FALSE),"INTAKE TEAM")))))), VLOOKUP(A2&"",[LPSMatch.xlsx]Sheet1!$A:$B,2,FALSE),"")
Any help? When I go to the function help all of the arguments are okay but it highlights the "" at the end of my formula.
fwiw, you can use Alt+Enter to add line feeds to your long formula and add a little legibility. The line feeds and 'white-space' do not negatively impact the formula's performance in any way.
    
All I had to do to get it working in its current state was at a ) to ... ,FALSE)), "") at the tail end.
There is some repeated logic that could be paired up. Line 2 could be OR paired with line 6 and 9 and line 11 seems completely redundant as you are still following the TRUE path for the first IF(C2<>"",... and the 'nothing matches' default appears to be doubled up. Here is my best shot.
=IFERROR(IF(C2<>"",
IF(AND(
OR(VLOOKUP(A2&"",[LPSMatch.xlsx]Sheet1!$A:$B, 2, FALSE)={"Assigned Attorney","Sales Team","Intake Team, Assigned Attorney, or Sales Team"}),
OR(B2={"Jimmy Edwards","Kathleen McCarthy"})), "Sales Team",
IF(AND(VLOOKUP(A2&"",[LPSMatch.xlsx]Sheet1!$A:$B,2,FALSE)="Intake Team, Assigned Attorney, or Sales Team",
OR(B2<>{"Jimmy Edwards","Kathleen McCarthy"})), B2,
IF(VLOOKUP(A2&"",[LPSMatch.xlsx]Sheet1!$A:$B,2,FALSE)="Assigned Attorney", B2,
VLOOKUP(A2&"",[LPSMatch.xlsx]Sheet1!$A:$B,2,FALSE)))), "INTAKE TEAM"), "")
An OR function (or AND function) can compare to an array of constants; e.g. =if(or("BCD" = {"abc", "bcd", "cde"}), ... would be TRUE. Using this method reduces the VLOOKUP functions significantly.
Footnote: the formula you are using is for an external workbook that is open. You would need full path(s) to the workbook if it is closed. If you get the formula working, close the external workbook and all of the full path(s) will be added.

Multiply numbers in Excel or LibreOffice cell contents by a constant when they are mixed with text?

I have a long series of cells written like this (example text):
Example Number (3502, 456)
How would I multiply the numbers by 4 without having to delete the text?
I also have cells in the format [sic below]:
Example Number (3502,456) (4560,250) (2345,223)
et cetera, there are on average ten parentheses per text string.
Occasionally, the text might also be only one word long, e.g.
Example (3205, 456)
or
Example (3205,456) (4560,250) (2345,223)
et cetera.
(all above is [sic]).
As a sort of newbie to Excel (well, really Libre Office Calc but it's essentially the same), how would I do this? I don't want to go through and manually multiply all the numbers myself. The number I want to multiply by is 4. I've tried just running a find-and-replace to replace all ,'s and )'s with *4's, but the program I need these numbers for can't evaluate expressions, it needs single numbers.
There are some 110+ items on each list I need to change, and just one math error on any of the three lists (!) and the program won't run correctly (I'm resizing an image, and the points I plotted on the image didn't scale up with it). I don't want to risk it.
It should be possible to do this with a macro but unless I'm mistaken LibreOffice macro code is quite different from Excel VBA.
However if you can afford to use several columns of your spreadsheet to figure the values out, you can do so using formulae. If cell A1 contains
Example Number (3502,456) (4560,250) (2345,223)
and B1 contains
=MID(A1,FIND("(",A1)+1,9999)
then this formula will return the 3502 as a number:
=NUMBERVALUE(LEFT(B1,FIND(",",B1)-1))
(9999 is chosen to be much larger than the likely length of any line, so the MID function will always return the whole of the rest of the text after the search character).
You should be able to combine MID and FIND functions in further cells to isolate the other numbers, assuming these are always found in the format (xxx,yyy) as per your example. Then you can use a final formula to rebuild the string from the multiplied numbers:
="Example Number (" & 4*C1 & "," & 4*E1 & ")"
and so on.
If your data has a variable number of numbers to find, some of your FIND functions may return a #VALUE error. You may need to use an IF function to exclude these, for example:
=IF(ISERROR(G1),"",G1)
would return the value of G1 if it contains data, but blank if it contains an error.
Here is a Python LibreOffice macro that does what you want. It assumes all of the values are in column A, and it writes the results to column B.
import re
def do_calculations():
document = XSCRIPTCONTEXT.getDocument()
sheet = document.getSheets().getByIndex(0)
cellrange = sheet.getCellRangeByName("A1:A10000")
row_tuples = cellrange.getDataArray()
row = 1
for row_tuple in row_tuples:
if row_tuple:
row = output_values(row, row_tuple[0], sheet)
def output_values(row, pairs_string, sheet):
"""Multiply pairs of values by 4 and output each pair to B column.
:param row: the row number in the B column
:param pairs_string: a string like "Example Number (123, 456) (789, 1011)"
:param sheet: the current spreadsheet
Returns the next row number in the B column.
"""
pairs = re.findall(r'\([^)]+\)', pairs_string)
for pair in pairs:
match_obj = re.match(r'\((\d+),\s*(\d+)\)', pair)
x, y = match_obj.groups()
result = "(%d,%d)" % (int(x) * 4, int(y) * 4)
cell = sheet.getCellRangeByName("B" + str(row))
cell.setString(result)
row += 1
return row
# Functions that can be called from Tools -> Macros -> Run Macro.
g_exportedScripts = do_calculations,
Save the code to a text file, for example calc_multiply_numbers.py. Put it in Scripts/python in your LibreOffice user directory. On my Windows system it is C:\Users\JimStandard\AppData\Roaming\LibreOffice\4\user\Scripts\python. If the python directory doesn't exist yet, create it.
To run it, open the spreadsheet and go to Tools -> Macros -> Run Macro. Under My Macros, click calc_multiply_numbers and then press the Run button.
EDIT:
I don't think you need to worry about the JRE error. On my system I can uncheck "Use a Java runtime environment" in Tools -> Options -> LibreOffice -> Advanced, and it still works. I just click "No" when it asks if I want to enable the use of a JRE now, and then it runs my python macro.
The reason it is not showing up under My Macros is because python is not able to interpret the file correctly. To find the error, test it with python using the following steps (assuming Windows):
Open a command prompt, for example by pressing Win, typing cmd, and clicking "Command Prompt" from the start menu.
Type cd "path-to-libreoffice/program". On my 64-bit system this is cd "C:\Program Files (x86)\LibreOffice 5\program" I use the normal Windows File Explorer to find the exact path.
Type "python.exe python-script". On my system it is python.exe "C:\Users\JimStandard\AppData\Roaming\LibreOffice\4\user\Scripts\python\calc_multiply_numbers.py"
The python interpreter will give an error message about the problem. If you are not able to figure out the message, write it in the comments below and I will help you.

Resources