Swapping the placement of a character in a cell - vba

I've been looking for a way to change the placement of a character within a cell with a macro, and have not been able to find exactly what I'm looking for. I've found ways to switch words (such as first name last name), but I need to switch a single character that is attached to the end of a number.
The report that's being filtered in registers negative numbers as:
2.00-
and I'm looking for an easy way to switch it to:
-2.00
as I am dealing with a massive number of records. Is there an easy macro that I can use to do this, or do I need to manually change these? Thanks in advance!

Select column then Text-to-Columns, Fixed width, Next, Advanced, Trailing minus for negative numbers, Ok, Finish.

With data in A1, in B1 enter:
=IF(RIGHT(A1,1)="-",-MID(A1,1,LEN(A1)-1),A1)

Create a new column and insert this formula. Replace A3 with the first cell in question, and then drag it down:
=IF(RIGHT(A3,1) = "-", LEFT(A3, LEN(A3)-1) * -1, A3)

Related

Use the same formula multiple times for multiple cells containing dropdown lists

My file looks something like this
image
An IF statement would be too long considering I have 20 different long formulas.
Update: I later tried to use an IF statement but failed because it depended on substitute function to replace cell references in the equation but substitute returned a string which coudn't be used as a function by IF.
User should be able to increase available rows by simply copy and insert the previous row.
I can use index match to copy a cell's value which contain the right formula according to the dropdown list but when the user select the same item again I can't update the formula with the new values without affecting the previous cell which used the same formula.I couldn't find a way to copy the same formula several times and replace cell references in it (without human interaction like search and replace) i.e. by using Substitute function which couldn't replace cell references as it looks through the cell's value not it's formula (the cell which contain the main formula).Here is one of the 20 formulas I have
=(Tables!O167*144/(Tables!O158*Tables!O159)/4005)^2*INDEX(Tables!A159:L200;MATCH(INDEX(Tables!A159:A200;MATCH(TRUE;INDEX(Tables!A159:A200>=Tables!O158*Tables!O159/(Tables!O160*Tables!O161);0);));Tables!A159:A200;0)+MATCH(INDEX(Tables!B159:B200;MATCH(INDEX(Tables!A159:A200;MATCH(TRUE;INDEX(Tables!A159:A200>=Tables!O158*Tables!O159/(Tables!O160*Tables!O161);0);));Tables!A159:A200;0)+MATCH(INDEX(Tables!B159:B200;MATCH(TRUE;INDEX(Tables!B159:B200>=Tables!O164/(2*Tables!O158*Tables!O159/(Tables!O158+Tables!O159));0);));Tables!B159:B200;0)-1;);Tables!B159:B200;0)-1;MATCH((INDEX(Tables!C158:L158;MATCH(TRUE;INDEX(Tables!C158:L158>=Tables!O163;0);)));Tables!A158:L158;0))I tried to use FORMULATEXT to convert the formula into a string then use substitute to replace the cell references then use the depreciated Evaluation function but hit the 255 char limit. I searched a lot on google but to no avail, I don't mind a VBA code but a macro free method would be better, Thanks.
TL;DR: Is there a way to copy a formula stored in a cell and replace some of the cell references then enter it in another cell multiple times with different cell references each time ??
Try this in E2 and fill down.
=CHOOSE(MATCH(LOWER(LEFT(A2)), {"r","s","t"}, 0), B2*C2, B2^2, B2*C2/2)

Excel 2016: IF function using position of cell relative to another cell

I'm trying to use IF to return a value that depends on the position of one cell relative to another in the same column.
Spreadsheet Example
If you click the above image, you'll see a number of columns with the possible values of "No," "Yes," "Yes>No," and "No>Yes."
The equation will go in the "Category of Change," row, one equation for each column. If the "Yes>No," is lower in the column than the "No>Yes," I want to return "Less Frequently," and if the opposite is true, I want to return "More Frequently" ("Same," if there is no "Yes>No," or "No>Yes").
I've tried using ARRAY and INDEX functions, but I'm not sure how to get Excel to "look" for each of those values, and then compare their ranking in the column.
Thank you in advance for your help!
MATCH will return the relative row number. This assumes the first column of data is in E2:E8.
=IFERROR(IF(MATCH("Yes>No",E2:E8,0)>MATCH("No>Yes",E2:E8,0),"Less Frequently","More Frequently"),"Same")
It is looking for exact matches, so if you have typos, it will always default to Same. If only one is found then it will still produce Same
You would put int he first cell and copy/drag over, the references will change automatically.

IF Function vba

I need a macro that can do this:
If column AB5 has a blank cell, then then column A5 will take the value from column U5.
if column AB5 is not a blank cell (contains text), then column A5 will take the value from AC5.
This will run for all the data at column AB
I tried to use IF function, =IF(ISBLANK(AB5), U5, AC5) but it will reflect the wrong data if the cell contains text where they will still take U5 value.
Ideally is if it can be done using macro, but IF function is also fine too!
Please help thanks!
I'd guess that your cells are not truly blank. My guess would be that AB5 has formula in it. Try:
=IF(LEN(AB5)=0,U5,AC5)
Edit
If it has a single space in there rather than being empty:
=IF(LEFT(AB5,1)=" ",U5,AC5)
or
=IF(LEN(AB5)<2,U5,AC5)
Perhaps try reversing the formula:
=IF(LEN(AB5)<>0,AC5,U5)
=IF(AB5<>"",AC5,U5)
As they are all 3 letter acronyms try this one:
=IF(LEN(AB5)>2,AC5,U5)
A foolproof way to be sure that there are no spaces as input errors:
=IF(LEN(SUBSTITUTE(AB5," ",""))=3,AC5,U5)
Let me know if any of these work, I can mock up a VBA function for you if they don;t but they should work.
Your function
=IF(ISBLANK(AB5), U5, AC5)
should work fine. If you drag down the formula in the A Column, the numbers in the formula should change:
=IF(ISBLANK(AB6), U6, AC6)
etc. Is this happening? What is your formula in cell A6?
=IF(AB5="", U5, AC5)
try that, should work

google spreadsheet array length varies. I'm left with -- after shorter array calculations

In google spreadsheet, my array length varies. I'm left with -- or a double dash after a shorter input is calculated and placed into the array or if i clear the input entirely.
Ex.formula =iferror(if(E10="",transpose(split(upper(D1),",")),query(vlist)),"")
The above will either take input from E10 or D1. If i clear all the input im left with -- in some cells. If shorter input is calculted I'm also left with -- in previous longer array positions.
Is there any way I can eliminate the possibliity of -- appearing in
cells?
Maybe I the original question should be, How can a fixed array
ignore null values and not output -- or double dash.
I have been struggling with this, too. And now i found a workaround to it in this forum answer.
The workaround is not to suppress the -- directly, but to handle them in the cells that use this data. You can handle them with the ARRAYFORMULA(IFERROR( functions.
I realized that if you have several cells where you use this data, instead of changing all these cells, a more comfortable way to do this is to
create an (invisible?) "helper" array somewhere else in your sheet, where you put your formula that creates the --
apply the workaround in the cell where you originally had your formula.
Example:
Cell A1 contains =SORT(UNIQUE(Sheet2!X:X)) (which eventually results in -- in the cells A2, A3,... if the number of unique values in column X on sheet 2 decreases).
Workaround: Use your formula =SORT(UNIQUE(Sheet2!X:X)) e.g. in cell B1 and put =ARRAYFORMULA(IFERROR(B:B)) in A1.

Linking cells in excel with a specific format

I am trying to link cells in excel on two different work sheets.
I am using the formula eg: cell1 = cell2 + cell3. The numbers that I have in cell2 and cell3 are in format of 100% (1) and 50% (2). I just want to add numbers 1 and 2 so that my cell1 will have number 3.
Is it possible to do without changing the cell formats?
Thanks a lot.
If you don't care about the percentages, just copy your column with the percentages and change the format of that column to value and in sheet 2, do addition on that column instead.
Unfortunately when a cell has a format of percentage and a user enters a number, it is converted into what it means given the context of the format. It's not like what is being displayed is wildly different than what is 'hidden' inside the cell. When you reformat a cell, that data is reformatted as well, so 50% becomes .5 even if you had originally entered 50 in the cell before changing it's format. Format is more than just 'display format' so maybe that's where the confusion is.
If you want to add the cells in the percentage row and not bother with reformatting the formula cell you can cheat and treat it as a string to get rid of that %. You could do =Left(A2+A3, Len(A2+A3)) that will give you the 1.5 answer without having to format te cell.
Not sure i understood your question but i'll give some elements:
formula and formats are separated in Excel, thus, you can set a formula in A1, say =A2+A3 but displays the value the way you wish
for instance, if A2 contains 100% and A3 contains 50%, then the result in A1 is worth 1.5
you can set the format of A1 the way you wish (Right-clic > Format cells > Number tab), for instance, decimal, the cell will then display 1.5 but if you choose percentage, the cell will then display 150%
Please elaborate your question if needed.
[EDIT] New answer thanks to your comment:
If i understand well, you want to sum up the values between brackets in your cell (whatever is before, event percentages in your case).
Then, you can try this in cell A3:
=MID(A1,FIND("(",A1)+1,FIND(")",A1)-FIND("(",A1)-1 )+MID(A2,FIND("(",A2)+1,FIND(")",A2)-FIND("(",A2)-1 )