My Excel Formula is not able to understand Dollar ("$") Sign? - excel-formula

I created an Excel File few months ago, See below.
Today wanted a slight adjustment in the formula.
But today if I go into the cell and just press enter it is giving an error at the first dollar sign? (marked in bold below)
If I remove all the dollar signs, the formula works again, but I don't want to as I have to copy paste the formula over a large range.
=LET(s,IF(TRIM(LOWER([#[FTC Conversion]]))="yes",[#[FTC Conversion Date]],[#[Start Date]]),t,IF(ISBLANK([#[Termination Date]]),DATE(2100,12,31),[#[Termination Date]]),
IF(TRIM(LOWER([#[Employee Type]]))<>"permanent","NA",
IF(TRIM(LOWER([#[Corporate Functions]]))="yes","NA",
IF(s>T$2,"NA",
IF(AND(s>=T$1,s<=T$2),IF(t>T$2,T$3&" New Joiner", "NA"),
IF(t<T$1,"NA",IF(AND(t>=T$1,t<=T$2),T$3&" Exit",T$3&" HC"))
)))))
I have already tried closing all excel sheets and re-starting excel, even re-started the PC as well.
Anyone has seen this before?

Related

How to insert a formula by macro?

The issue has been solved.
It would appear that when I made some changes to capture data a little while ago, I inadvertently broke the order of things. When the above bit of code was running, the [Date Out:] column was indeed empty, so Excel was reporting properly.
I've since reordered the input of formulas and now the sheet works correctly, with credit to #BigBen and #Michael Wycisk.
I created an Excel sheet to draw together the data from several other Excel sheets into one to keep track of a project.
I have a formula that works if it is written into a range of cells with the source data sheet open in the background. If I ask a macro to put it into the required cells as the main sheet opens then the formula fails. By 'fail', I mean the formula checks it's first column to see if data is present or not and then decides that the column is empty regardless, therefore falsely reporting 'nothing sent' if there is a date in the "Date Out" column.
Here is the line in question.
WSR.Range("ReportTable[Latest Portare Instance:]") = "=IFERROR(IF([Date out:]="""",""Nothing Sent"",IF(AND([Received by Serial:]="""",[Received by Asset:]=""""),""Not Received"",IF([Received by Asset:]<>"""",LOOKUP(2,1/('Stock Movement Archive Defra.xlsx'!Archive[Asset No:]=$J2),'Stock Movement Archive Defra.xlsx'!Archive[Location:]),LOOKUP(2,1/('Stock Movement Archive Defra.xlsx'!Archive[S/No:]=$I2),'Stock Movement Archive Defra.xlsx'!Archive[Location:])))),""Issue"")"
It's one of several formulas, all inserted the same way and the rest work. As far as I can tell the formula is being inserted correctly, just that this one stops at the first if statement.
For reference, I have tried changing the first 'if' statement to start IF([Date out:]<>"""", the formula then either states "Nothing Received" where there is no date or pulls the correct data if there is a date. Also tried changing the format of the "Date Out" column.
The formula looks fine for me. The only problem might be that you need to use the .Formula property after the Range object:
WSR.Range("ReportTable[Latest Portare Instance:]").Formula = "=IFERROR(IF([Date out:]="""",""Nothing Sent"",IF(AND([Received by Serial:]="""",[Received by Asset:]=""""),""Not Received"",IF([Received by Asset:]<>"""",LOOKUP(2,1/('Stock Movement Archive Defra.xlsx'!Archive[Asset No:]=$J2),'Stock Movement Archive Defra.xlsx'!Archive[Location:]),LOOKUP(2,1/('Stock Movement Archive Defra.xlsx'!Archive[S/No:]=$I2),'Stock Movement Archive Defra.xlsx'!Archive[Location:])))),""Issue"")"
To make sure that your formula is correct (you say it works fine when typed into the cell), you might type it into the cell, select the cell and then type ?ActiveCell.Formula into the Immediate Window inside the VBE (don't forget to check that the quotation marks are correct).

How do I enter a formula in VBA? [duplicate]

This question already has an answer here:
Excel VBA Formula German/French/Italian/Russian/Dutch/Foreign Function
(1 answer)
Closed 3 years ago.
I'm making a bot that erases certain columns and fills them in with new data. By erasing the data, the formula becomes
=IFERROR(INDEX('AP query'!O:O,MATCH(Findings!#REF!,'AP query'!L:L,0)),"Non PO")
So I tried making a macro and filling the cell with the formula but it says there's an error. Is there a fix or another way to enter the formula into the the cell using macros?
Range("B3").Formula = "=IFERROR(INDEX('AP query'!O:O,MATCH(Findings!C3,'AP query'!L:L,0)),"Non PO")"
srcWorkbook.Worksheets("Findings").Range("B3").Copy
srcWorkbook.Worksheets("Findings").Range("B3:B" & LR).PasteSpecial xlPasteFormulas
When you wish to use a string in a formula =IF(A1="Hi",... in VBA, just "double up" the quotes:
Range("B3").Formula = "=IFERROR(INDEX('AP query'!O:O,MATCH(Findings!C3,'AP query'!L:L,0)),""Non PO"")"
Because, as VBA compiles that line, it'll hit the first quote at "Non Po" and think that's the end of the line. So (...trying to visualize it), it'd be reading that line like your formula is:
=IFERROR(INDEX('AP query'!O:O,MATCH(Findings!C3,'AP query'!L:L,0)),
Tangiental tip - sometimes when I hit similar issues, even just pasting the code here on SO, and formatting it as code, helps because as you can see in your post, the Non PO is a different color, but all formulas (strings maybe?) should be the same (all red, as in the answer I posted above).

AGGREGATE formula not automatically calculating when written to results spreadsheet

I have a python 3.7 script that has been developed using the OPENPYXL (v2.5.10) library to take data from a number of excel workbooks, to process that data and then to write to a separate excel workbook. The results workbook contains around 100 named ranges and numerous formula which all work as expected including automatically calculating when the workbook is opened in excel.
I am having trouble with one particular formula group which includes the AGGREGATE function. In this case the formula writes to the results workbook, to the correct cell and in the correct form. While other formulas show the resulting value on opening the workbook, this sequence of formulas only show a result if you select the cell, place the cursor in the formula bar (as if you are editing the formula) and then you push the enter/return key. No change or edit is made to the formula. Once you have done this the formula works as expected.
I have tested this on both the latest macOS and windows versions of excel and I get the same behaviour. I should add that trying the 'calculate now', CtrlShiftAltF9, and 'calculate sheet' options do not have any impact. The only time the formula calculates is if you use the enter/return key.
The code that writes the formula is:
activeSheet.cell(row, col).value = f"=IFERROR(INDEX({rngData}, AGGREGATE(15,3,({rng}={cellRef})/({rng}={cellRef})*ROW({rng}),{nth}),{colIndex}),\"\")"
which gives, for example, a correct result in the excel workbook cell as:
=IFERROR(INDEX(_monthAgedDebt_Data, AGGREGATE(15,3,(_monthAgedDebt_ProjectNumbers=$L$4)/(_monthAgedDebt_ProjectNumbers=$L$4)*ROW(_monthAgedDebt_ProjectNumbers),1),6),"")
So in summary:
the code works as it writes the correct formula to the correct cell and in the correct form
in excel the formula does not automatically calculate but only works if you edit the formula in the cell, make no changes, and push enter/return to exit the edit
Is it an issue with AGGREGATE producing an array result? I chose this form of formula principally because you do not need a CTL-SHIFT-ENTER to make it work. If you enter it directly into a cell in excel you can enter it as a normal formula.
I haven't been able to find help on stack overflow other than this one. However, the solution proposed here doesn't work either.
This question poses a similar issue but has no relevant responses.
This question may hold a clue but I don't seem to be able to make that work as well.
Any thoughts on how to fix this issue appreciated. I am not sure if it is an openpyxl issue or an excel issue and am not sure what else to test.
All - the final answer for completeness.
It turns out that the key to solving this issue lay with OPENPYXL and that the guidance provided in the answer by Charlie Clark to this
question
was correct. I had initially applied the solution incorrectly.
I changed the formula to:
activeSheet.cell(row, col).value = \
f"=IFERROR(INDEX({rngData}, _xlfn.AGGREGATE(15,3,({rng}={cellRef})/({rng}={cellRef})*ROW({rng}),{nth}),{colIndex}),\"\")"
by adding in the '_xlfn.' to the front of the AGGREGATE function statement.
The excel spreadsheet now works as expected without the need to edit the cell containing the formula.

Excel 2016 seemingly randomly changes number values I enter

Today I encountered a really weird error in Excel 2016 16.0 (on Windows 10.1) that is driving me crazy:
When I enter the number 2.089E-7 into a cell that is formatted as either standard, number, or scientific, excel changes the value to 2.09E-4.
When I click into the cell, the bar on top tells me the value of the cell is 0.0002089, which is exactly the number I entered, except that three decimal orders of magnitude are missing.
I played around a little bit and found out that Excel does this for all numbers that have more than three decimals in the format X.XXXE-7. If I enter, for example, 2.10E-07 the value is correctly stored as 0.00000021.
I have tried everything that came to my mind, including formatting the cell to all available types, closing and re-starting Excel.
What is wrong with my Excel version?
Thanks in advance!
EDIT for clarification:
Numbers I enter, vs. values that get stored:
2.1E-7 vs. 2.1E-7
2.11E-7 vs. 2.11E-7
2.111E-7 vs. 2.111E-4
2.1111E-7 vs. 2.1111E-3
2.11111E-7 vs. 2.11111E-2
and so on...
You are right to try formatting, because this seems like a formatting issue. Select your cell and try this button in the Ribbon and see if that works.

Excel INDEX + MATCH and LEFT/RIGHT

So I have this:
=IFERROR(SUM(INDEX('Roster Hours'!$B$6:$AB$36,,MATCH($J17,'Roster Hours'!$B$5:$AB$5,0))),"")
J17 is a name, and it pulls their total rostered hours for the month from a mostly VB generated spreadsheet. I'd like to leave that alone.
This issue is, the VB has code to replicate fortnights, to save the user entering them. When it does this, it places an asterix at the start, and it gets ignored by the formula.
Is there a way to modify the code above to trim the first character. I know the code to trim it, but applying to a range of numbers is the issue.

Resources