appending negative sign to number in excel - excel

I have excel file in which for a particular column I have +/- sign numbers. like
123.32-
452.23
456.80-
When I am doing sum I am not getting the correct value.
How can bring the - sign to front so that I can get rite sum.
I want numbers be like
-123.32
452.23
-456.80
Thanks in advance!!

Solution 1
Use this formula
=IF(RIGHT(A1,1)="-","-"&LEFT(A1,LEN(A1)-1),A1)*1
See this for details.
EDIT :
Solution 2
This can be done without using formula also using Text To Columns feature, see this.
On the Excel Ribbon’s Data tab, click Text to Columns
Click the Next button in Steps 1 and 2
In Step 3, click the Advanced button
Add a check mark to the option, "Trailing Minus for Negative Numbers"
Click OK, and then click Finish

This is my proposal:
=IF(RIGHT(A1;1)="-";VALUE(LEFT(A1;LENGTH(A1)-1)*-1))
If you have - at the end, take the A1 cell without the last sign. Then make it to value and multiply it by -1 for negative. Thus, the result would be a number.

Related

Is there a formula to increment by 0.1 to an alphanumeric code in Excel, and then repeat the pattern?

I'm trying to make a column going all the way down like this:
C00
C00.1
C00.2
C00.3
C00.4
C00.5
C00.6
C00.7
C00.8
C00.9
C01
C01.0
C01.1
C01.2
C01.3
....
C01.9
C02
C02.0
C02.1
AND SO ON.
Is there a way to do this easily on Excel? So far I've just been doing the drag and drop after each x0x.0, but I'd really just like to automate this and save time. Thanks in advance!
Try this method.
Enter this formula in the first cell in which you want the number.
=TEXT((ROW()-1)/10,"""C"""& IF(MOD(ROW(),10)=1,"00","00.0"))
Adjust the -1 to the number you need, depending upon the row number and result number you want. As the formula is it will write the number "C00.1" if entered in row 2. Note that the "1" in the expression MOD(ROW(),10)=1 is the same absolute number as the "-1" just mentioned. This expression determines which is each 10th number that needs a different format.
Copy down the formula for as far as you need the numbering. You may wish to change the formulas to hard text. If so, Select > Copy > Paste Special > Values.

Excel apply a formula to same cell

It could be a basic one, trying to apply formula =TEXT(A2/(24*60*60),"dd \d\a\y\s hh:mm:ss") on the same column Seconds to a new computed value. For eg., 495079 tranform to 05 days 17:31:19. I don't want to bring in additional columns. Any help is appreciated.
Duplicate: this answer.
#MADHU VS - your formula is exactly like the one in that answer. Maybe what's confusing you is you think the answer should be 5 days - it's really 4. "04 days 17:31:19"
The person who answered on the other thread also made a useful suggestion not to use the text function. Use =A2/(24*60*60) on your sheet, then go into the time formatting dialog and set up a custom format dd \d\a\y\s hh:mm:ss.
I just tried that, and it works perfectly. I was able to subtract 1 from it in a different cell, and got "03 days 17:31:19" (if that would be useful to you).
24*60*60 = 86400.
Enter =86400 in a cell. Copy that cell. Just select the range of the "Second" numbers only (not the entire column) and right click then select Copy paste special, select divide (Also select values if so desired), click OK. No need for another column.
Then format cells pressing Control + 1

How to Sum value from current cell plus input cell

I have two problems:
How to make a cell input? I need to enter a number and after pressing "enter" delete the number so I can add more input.
How to SUM the entered input with the value of another cell, for example C3 and store the result on C3?
I don't know how to delete the cell after pressing enter.
I've tried writing at C3 "=SUM(C3+F3)" and "=0+SUM(C3+F3)" both gave me a #REF ERROR.
Case:
I want to know how much money I have spent in one day. So C3 cell at the beginning have a 0 and F3 cell (input) is empty.
The point is if I buy a $3 souvenir, write 3 at F3, press enter (delete the 3 to make F3 empty) and make a SUM with whatever was at C3 plus that $3.
I would create a button, then it is clearer what you want to happen, though you could hook into the key press.
Go to File Options Customise and customise the ribbon to add the Developer tool bar.
on the Insert command, add a new button to the form. It will ask which macro you want, click New
Past this code:
Sub Button1_Click()
Range("F3").Value = Range("F3").Value + Range("C3").Value
Range("C3").Value = ""
End Sub
into the button click, and then when you click the button it will take the value in C3 and add it to F3 and then clear the value in C3.
Remember to save the workbook as MACRO ENABLE WORKBOOK, else the macros won't save.
click button
Hope that helps
Overwriting the same cell with different values and then expecting a sum of the previously entered values is not a good approach. If you want to understand why the result is a specific value, you need to be able to see which values contributed in which way to that result.
The better approach is to list all different numbers in one column and then calculate a running total in another column. Just like a bank statement. A bank statement shows you the current balance, but also each transaction, debit or credit, that went into calculating that balance. If you did not see the transactions, you don't really know if your pay check has already been included in the balance or not.
If you overwrite the same cell multiple times, how do you know if you have made a mistake and entered the cost for lunch twice, or made a typo in the numbers?
So, enter the data in rows. Each data point in a new row. Maybe use a column for date, one for money spent. Then use simple formulas in other columns to calculate what you want to calculate. You won't need any VBA or script or buttons for that.

How to shrink column width with multiple-line custom number formats?

I discovered a trick, but Excel doesn't want to cooperate fully... but maybe there's a workaround...?
I often end up with a date/time on a "tall row" (since other columns are multi-line):
...and I'd like to save vertical space by splitting the date/time onto 2 lines, while keeping it a single numeric value for reasons of sorting, etc:
I realized that this can be accomplished by using a ␊LineFeed character in the custom number format, one of two ways:
Method #1: On a keyboard with a numeric keypad:
Select the cell with the value.
Hit Ctrl+1 to open the Number Formats dialog.
Choose the Custom category and then in the Type: textbox:
Enter the first part of your custom format, ie. yyyy-mm-dd
While holding down Alt enter 0010 on the numeric keypad, and then release Alt
Enter the second part of your custom format, ie. HH:mm am/pm
Hit Enter.
Drag between the row headers to make the row twice as tall:
If Wrap Text is not already on, click it on the Home tab of the ribbon:
👉 Alt + 0010 enters a ␊LineFeed character.
Note: Since Excel doesn't expect this character, the first line you enter in the Type box will disappear as soon as you enter the ␊LineFeed character. There's no way to see it within the dialog (without deleting the ␊LineFeed), but it's still there.
Method #2: On a keyboard without a numeric keypad and/or using VBA:
In the VBA Editor, either within your procedure, or in the Immediate Window (Ctrl + G), you can set the number format for A1 with something like:
Range("A1").NumberFormat="yyyy-mm-dd" & vbLf & "HH:mm am/pm"
...then adjust the row height and make sure Wrap Text is on, via VBA or with steps #5 & 6 above.
👉 vbLf (or Chr(10)) represents a ␊LineFeed character in VBA.
My issue:
This is cool, but it seems that Excel still treats the value like it's one long string on a single line.
This is demonstrated by:
double-clicking between column headers to AutoFit the column:
The column does not "shrink" any further.
double-clicking between row headers to AutoFit the rows:
The row does not "grow to double height".
manually dragging the column to a narrower size.
Excel "thinks" the value doesn't fit:
               
Any ideas for a workaround?
Perhaps there's a hack to force Excel to display partial values instead of ###### when a formatted numeric value doesn't fit?
Thanks!
You have to shrink-wrap it. See the OP's edit here:
Prevent hash signs (#) showing up in Excel without changing cell format or width
Go to the Alignment tab in the Format Cells dialogue.
Select "Shrink to fit".
Select "Wrap text".
Click "OK".
Excel will still auto-size the column to ~139 pixels, but you can drag the column width to ~71 pixels and still see both lines.
Make sure the Shrink to fit function is ticked
Go to: Right click on cell --> Format Cells --> Alignment --> Shrink to fit
For this example, you can split on two cells instead of doing that. On the first cell, just put the date format without time. On the second cell, do a formula =(the first cell), but put it in time format.
I am looking at a way to shrink this to fit on multiple lines in a cell, but it looks like we don't have the technology to do that automatically in 2020.

Add blank column to query

Is there a way to add a blank column to a query in Query Studio? I tried to use a calculation on an existing column but the only options that I get are for First Characters, Last Characters, Concatenation, and Remove Trailing Spaces. None of these options allow you to enter a decode, case or IF statement.
Any assistance is greatly appreciated. Thanks.
It's a bit of a hack as Query Studio is really all about making it easy to get data and doing anything with layout is really a job for Report Studio, but you can do the following:
a) create a calculated column on a text field. Select 'Concatenation' as the operation and put a space as the preceding text. Click ok
b1) right-click on the new column and select 'Format', then 'Text' and enter 1 for the number of characters
or
b2) create another calculated column from the first calculated column, set it to 'first characters' and enter 1 for the number of characters. The first calculated column can now be deleted.
Both of these approaches will give a column that only contains a single space - not actually blank but close enough for most purposes. The first approach is a little quicker but may result in the text still existing in some output versions (e.g. csv) - I'd need to do more testing to confirm.
The column title can be edited (to be set to blank) by double clicking it, of course.

Resources