I wrote this simple formula in an Excel sheet.
=CONCATENATE(A$1,"='",A49,"', ",B$1,"='",B49,"', ",
C$1,"='",C49,"',",D$1,"='",D49,"'")
It combines the cell value of the current row with the column headers.
I put it on E49 and if I copy-paste it anywhere in column E it adjusts nicely. I want to improve it and make it more generic and I'd rather not use VBA to keep it simple (i.e. install on any spreadsheet with simple copy paste of cell formula.)
FEATURE DONE:
Automatically adjust to change the label in column headers.
FEATURE MISSING:
Adjust to add/remove columns by editing a few characters (e.g. having a "A:D" or "A1:D1" argument in the formula. )
Automatically adjust to add/remove columns.
QUESTION:
Can I do that with a formula only? If not, is there any formula that could get close to the same result?
it depends on how complex you want the formula to be. I think its a less elegant solution, but you could theoretically build a huge IF(..) statement to test if column names exist.
IF they are not blank, perform the concat.
personally, I would use VBA, and toss it into an Add-in; that way it would open within any instance of excel on the local computer.
Related
I am trying to reference a column in an external Excel document in my formula, and then expanding said formula to the right to auto-fill the remaining cells. I have some values in the formula that I want to not auto-increment, which have been locked using absolute references ($), and others that should increment. But when it comes to the references to the external worksheet columns, those increment even though it makes no sense for them to do so.
Consider this formula as an example, with A1 through A* being a series of dates:
=COUNTIFS(external_sheet[date]; ">="&A1; external_sheet[status]; "ACTIVE";)
If I were to expand this formula to the right, it will increment [date] and [status] to the next column in the sheet. I do not want this behavior, but as far as I can tell there is no way to lock down these values as you can with absolute references. I tried adding a $ symbol before the external sheet reference, but that just breaks the formula.
An option would be to do external_worksheet!$A:$A instead, but for my use case it would make more sense to use references to named columns, as the order of columns may change between data files.
Figured it out after some more Googling (and learning that this is called a "structured reference"). Apparently, the syntax is this:
=COUNTIFS(external_sheet[[date]:[date]]; ">="&A1)
This will make sure that date does not increment to the next column name when filling to the right.
Thanks, I hate it.
I am having difficulty getting a timestamp to remain static (unchanging) each time a worksheet derived from an Excel Userform is opened. The goal is to have the cells in Column C provide a prefix and timestamp mmddyyhhmm (e.g., C106CS1130181200) that is determined by the information in Column G.
Currently, in "Sheet1", I have Columns A-G trying to workaround this problem.
Column A formula:
=IF(SurvData!G2="Confined Space Surveillance","C106CS",IF(SurvData!G2="Asbestos Surveillance","C106AP",IF(SurvData!G2="Electrical Frisking","C106EF",IF(SurvData!G2="Fall Protection Surveillance","C106FP",IF(SurvData!G2="Hearing Conservation","C106HC",IF(SurvData!G2="Tracked HM Storage Location","C106HM",IF(SurvData!G2="Hot Work Surveillance","C106HW",IF(SurvData!G2="Hexavalent Chromium","C106HX",IF(SurvData!G2="Hazard Communication","C106HZ",IF(SurvData!G2="Job Safety Analysis","C106JSA",IF(SurvData!G2="Lockout/Tagout Plus","C106LT",IF(SurvData!G2="Operational/Out of Service","C106OOS",IF(SurvData!G2="Lead Surveillance","C106PB",IF(SurvData!G2="Personal Protection Equip","C106PPE",IF(SurvData!G2="Respiratory Protection Surveillance","C106RP",IF(SurvData!G2="Shop Safety Surveillance","C106SI",IF(SurvData!G2="Ship Safety Surveillance","C106SS","")))))))))))))))))
Column B Formula: is identical to Column A
Column C Formula:
=IF(B2="","",timestamp())
Column D Formula:
=IF(AND(SurvData!C2<>"",SurvData!G2<>""),Sheet1!B2&C2,SurvData!C2)
Column F Formula:
=CONCATENATE(A2,C2)
The worksheet labeled SurvData Column C cells contain a formula to get the result of a Serial ID from Column F, Sheets1. Regardless of my efforts, the timestamp seems to change when the SurvData worksheet is opened.
Is there a way to write VBA in a Worksheet Change event that would allow me to combine the nested IF() Statement above with a timestamp and have it remain static (non-changing)?
There are two ways to accomplish this. The first is using a timestamp formula.
This will work:
=IF(TargetCell<>"",IF(TimestampCell<>"",TimestampCell,NOW()),"")
For this to work you will need to enable circular references. To do that head to the options in excel -> Formulas -> Check the box that says "Enable Iterative Calculation".
That will create a timestamp in a cell as soon as the target cell is changed. However, I strongly urge you to create one single cell in your sheet and have it contain the formula =NOW() and have every other formula that needs the current time to reference that cell.
Create a list of strings, possible entries for what would appear in the G column. Do this in a separate worksheet. Then add the list of codes the strings mean next to it. Do a VLOOKUP or do INDEX/MATCH and pull the answer. Something along the lines of =INDEX('NewLookupSheet'!$A$1:$B$17,MATCH('SurvData'!G2,'NewLookupSheet'!$A$2:$A$17,0),2)
To provide a VBA solution, I would need more information to edit this and update the answer. As it stands, there is no clear VBA solution to provide other than pseudo-code as there is no clear information on what has already been attempted or what the VBA is attempting to accomplish differently from a formula solution.
I'm trying to use formula to copy data from one worksheet to another where a column matches a certain value.
To be more specific, I want Working!A2:E100 to contain Data!A2:E100 but only for those rows where Data!C2:100 contains the value "Fixed".
Doing this with leaving blank rows is simple, I just create the formula:
=IF(Data!$C2="Fixed", Data!A2, "")
And copy that formula across all the cells.
But then I thought I'd get clever and have it not copy across blank lines, and entered a maze of unclear excel tutorials and vague error messages.
I've created this formula:
=INDEX(Data!A2:Data!A200, MATCH("Fixed", Data!$C$1:Data!$C$200, 0))
And entered it as an array formula using ctrl shift enter.
However all I get is the contents of Data!A2 repeated over and over in every cell of my spreadsheet.
Does anyone need to know what I need to do to make this work?
This is my attempt at a local prototype following the example in BruceWayne's answer, the results are visible:
As you can see "Row 2" just appears repeatedly in the result column. Excel doesn't seem to have an easy way to see what version it is any more but this seems to be a pretty recent one, it's got the ribbon with the file menu and all menu headings are capitalized.
Here's a formula you can use (note: enter this as an array):
=IFERROR(INDEX(A$1:A$200,SMALL(IF(C$1:C$200="Fixed",ROW(A$1:A$200)-ROW(A$1)+1),ROWS(A$1:A1))),"")
You may need to tweak the ranges, I think I got them to match yours, but again, probably need to tweak. You can then drag this down, and it'll fill in with the values from column A, skipping any blanks.
Edit: Here's a screenshot to (hopefully) help show what I did:
You can edit the ranges, naturally, to be over two sheets.
To clarify, A$1:A$200 is the range of what you want to return (the index). C$1:C$200 is the range that holds "Fixed".
I have an excel sheet with three sum functions. The sheet is a template, so the rest of the sheet is blank, except for a couple text descriptions in Column A.
I use an ETL process (Talend Open Studio) to open the worksheet, input some data, append a couple other sheets, and save this different worksheet in a file share.
When I open the worksheet in the file share, the three cells with the sum functions show as zero, but when I double-click the cell, they calculate correctly.
I would like for the cells to show their calculation without me double-clicking them.
The cells are formatted as General, and the Calculation option is set to Automatic. What can I do?
select all, find-replace = with = and excel will see the contents as a formula.
I have seen such problem occurs when exporting data from "NoSQL" databases such MongoDB, etc.
You can insert a column in right side and go to the "Data" tab -> "Text to Columns" option.
Make sure you select appropriate format while separating.
Whatever you want to separate will shift to right side. Now delete this undesired column. You are done.
It is possible that Excel is seeing the cells as Text, despite the fact that you have formatted as General. This can be the case when dealing with data coming from an ERP such as SAP.
Try these two approaches to see if one works:
Approach 1
Transfer your data to another sheet by Copying your data cells and paste special (values) into another sheet
Then copy and paste your formulas into the other sheet and see if that works.
Approach 2:
For all the cells you're having trouble with, enter formula =Value([your cell]) in fresh column
Copy that column and Paste Special Values over it
Point your formulas to this new column
It's hard to reproduce the problem you're having unless you have a datasource that is exhibiting the issue. But one of those approaches may help.
How that idea worked for me:
Assumption: Source Data in Column A2
Data is "$4,238.74 "
In B2 = RIGHT(A2, LEN(A2)-1) to clear the leftmost and stubborn character ("$" that would not clear with find and replace)
In C2 = LEFT(B2, LEN(B2)-1) to clear the rightmost and stubborn character (identified as unicode 160 that would not clear either)
After the above cleaning was done the cells still would not work with something as simple as SUM() without double clicking each cell manually.
Since that is not efficient User6574133's divide by 1 idea was applied:
In D2 = C2/1 this called the stubborn (C2) cell that wouldn't calculate and created workable clean data in D2 that would calculate without having to double click each cell manually.
In a blank column Put divide the same number by 1 (eg = 5.223/1 = 5.223) Problem solved
It could be that you have calculations set to manual instead of automatic. To fix this, go to the Formula tab/Calculation/Calculation Options/tick Automatic.
I fixed mine merely by going to formulas, calculation tab, "calculate now". It woke Excel up.
Actually, go to Formulas, Calculation Options, and you will see it is set to MANUAL, change it to AUTOMATIC. I believe some update must have changed it to Manual.
I solved in a very simple way: try saving the file with OpenOffice.
How does one cell obtain the formula of another cell as text without using VBA? I can see this question has already been asked many times and the answer is always to write a custom function in VBA.
However, I found a post made in 2006 which claimed to have found the non-VBA solution but the link provided in that post is already broken.
=FormulaText(Reference) will do the trick Documentation
There is nice way of doing this without VBA. It uses XL4 macros (these are macros, but it is not VBA, as asked).
With reference to the figure 1, cells A2:A4 contain usual formulas.
Going to Formulas -> Define Name, I defined two named ranges (see fig. 2), with the information shown in cells A6:B8.
Enter in cell B2 =FormulaAsText. This will retrieve the formula in cell A2 as text.
Explanation:
The named range FormulaAsText uses =GET.CELL(info_type,reference). In this case, ìnfo_type = 6 retrieves the formula, and reference = OFFSET(INDIRECT("RC",FALSE),0,-1) uses the cell with 0 rows and -1 columns offset from the one the formula is used in.
Copy B2 and paste into B3:B4. This will show formulas in A3:A4. Cell A4 shows that the worksheet function CELL only retrieves values, not formulas (as opposed to GET.CELL).
Since FormulaAsText gets the formula from a cell at fixed offset (0,-1) from the current, I defined another range FormulaAsText2, which uses an offset (rows,cols) read from the worksheet itself. Cells D2:D4 contain =FormulaAsText2. Thus, cell D2 shows the contents of cell B3 (=OffSET(D2,1,-2)), which is FormulaAsText. cells D3:D4 show the contents of themselves. This adds some flexibility. YMMV.
PS1: The essence was taken from
http://www.mrexcel.com/forum/excel-questions/20611-info-only-get-cell-arguments.html
PS2: Tim Williams mentioned in a comment "the old XLM GET.FORMULA()". This answer is possibly related (not the same, since this one uses GET.CELL()).
PS3: A simple VBA solution is given, e.g., in
http://dmcritchie.mvps.org/excel/formula.htm
EDIT: Complementing this nice answer, the worksheet function FormulaText is available for Excel 2013 and later.
This suggestion may be helpful for those who after retrieving a block of formulas and transporting them to a new spreadsheet want to put them to work again. Excels FORMULATEXT function is great for picking up formulas but it leaves them as unusable text strings. If you want to get them back as fully functioning formulas you have to edit each one individually to remove the string character, but here is a shortcut for larger blocks.
Get to the position where you have the required formulas as text (in other words after using FORMULATEXT - you have done a copy and (value only) paste). The next step involves highlighting all the cells you want to convert and then navigating to the [Text-To-Columns] menu option ({Data} bar on Excel 2016). You can select 'Delimited' but on the next screen just make sure you de-select any marks that do appear in your formulas. Then 'Finish'. Excel should automatically analyse the cells as containing formulas and you should now have them working again.
There is a way to do this. In my example I had a table that showed a date. The date comes from Sheet!G91. In my table I also had a column that showed the sheet name. I added two more columns to my table. The first column had column(Sheet!g91), which returns the number 7, because G is the seventh letter in the alphabet. I then converted the number to a letter (G) using another table in my workbook. In the second column that I added, I made a formula row(Sheet!G91), which returns the number 91. Note: Row and Column may appear as volatile formulas, which recalculate with every calculation of the workbook.
I wanted another column to show the formula contents of the date cell mentioned at the beginning of this post. I included the following string function (you can also use CONCATENATE).
"=" & AJ9 & "!" & AM9 & AN9
The items separated by ampersands get strung together (that is, concatenated). AJ9 in my example contains the sheet name, AM9 contains the column letter, and AN9 contains the row number.
I now have a column that dynamically updates its contents to reflect the sheet name and cell reference. The results in my workbook cell are
=Sheet!G91.
You can't. This is most likely a design choice to eliminate an average Excel user from accidentally getting something they did not want.
What you are reading is correct - writing a UDF is the solution you want.