Adding a text to the same cell - excel-formula

In order to save time and simplify my work I need to add the particle "lbs." to every cell I enter a value on.
if I type 123, I need it to automatically read 123lbs

you can custom format the cells:
#.# "lbs"

Related

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.

How to use an input mask in excel vba?

READ CAREFULLY THE QUESTION PLEASE, IT MENTIONS EXCEL VBA.
NOT EXCEL
I was given the task of fixing a date input on a VBA form. A textbox should have the user enter the date as MM/DD/YYYY.
I am required to use an input mask, not allowed to do something as validating date after or using a calendar. So far I was able to use the 2 methods mentioned (forcing the format after using ISDATE).
However, it has now been made clear it has to be a mask so keys are filtered on entry, with the mask being visible when entering the date: __/__/____
Where you see underscore, he should only be able to enter numbers and the / are always at those positions
Is there a way to do this? I can only find a tutorial for the mask in Access VBA.
I Googled "Excel input mask" and the 2nd result was: Using an Input Mask Microsoft Excel written by Allen Wyatt...
Using an Input Mask
...You may wonder if there is a way to set up an input mask that will add the colon automatically. The good news is yes, there is. The bad news is no, there isn't. Sound confusing? Let me explain...
You can set up a custom format that will display your time in any format you want. For instance, you could use the following steps:
Select the cells you want to use for time input.
Choose Format from the Cells menu. Excel displays the Format Cells dialog box.
Make sure the Number tab is displayed.
In the Category list, choose Custom.
Replace whatever is in the Type box with #":"00.
Click on OK.
You can now enter your times using just digits. The problem (and this is the bad news) is that the cell doesn't really contain a time. If you enter 230 (for 2:30), it doesn't contain 2:30 as a time—it contains two hundred and thirty. Thus, you can't use the contents of the cell directly in time calculations.
To overcome this, you can use another column to show the entered digits converted into a time. All you need to do is use a formula to do the conversions. For instance, if the time you entered was in cell A3, you could use the following formula in a different cell to do the conversion:
=(INT(A3/100)/24)+((A3 - (INT(A3/100)*100))/1440)
Format the cell that contains the above formula so it displays one of the various time formats, and you are all set.
(Full article and more at the source.)
This post may help you...
Formatting MM/DD/YYYY dates in textbox in VBA

Loop through column, search for text, get value of X

I would like to create a CommandButton macro in excel to determine if the name is the same with the one I'm searching for and if it is the same I will be getting the value of the cell beside it and add it all together to get the final amount.
This will be the example that I would like to do:
this will be the flow:
I will first check if the cell value is the same with the name
If it is James I will get the amount and add it to the total value for James, same goes for Ramirez
After everything is checked the accumulated value will then be placed on the cell beside James/Ramirez's name
Is there a way to do this in Excel? or any faster way to do this without using a commandbutton?
You don't need to use marco for this.
You can simply type in a function
In the example shown below,
E2:=SUMIF(A2:A6,D2,B2:B6)
E3:=SUMIF(A2:A6,D3,B2:B6)
EXPLANATION
=SUMIF(range_where_the_keyword_will_be,term_to_search,corresponding_values)
If you type "Ramirez" in D2, E2 will give you "300".
TIPS
If you want it to give you a message (such as, "not existing"), when you type in a name that is not in the list, you can try the function below.
=IF(COUNTIF(A2:A6,D2)<>0,SUMIF(A2:A6,D2,B2:B6),"Not existing")

Excel weird behaviour with dates => text

I have a ton of cells that contain dates such as 22/12/2013. This is set automatically as Date format. And if I try to change the cell format to text (Simply because I want it to be text rather than a date so that I can read it later with PHP), the thing changes completely.
Here's how to replicate the error.
Write in a cell 22/10/2013
Change the format to TEXT
The original content gets changed to 41569
I need a way to fix this, because otherwise when I read the date with PHP, it gets convereted to 41569 nonetheless. But if I manage to make it text, it will be alright.
As andy holaday says, using cell formatting to change the format won't actually change existing numbers (dates) to text. You can do that with "text to columns" functionality:
Select column of dates > Data > Text to columns > Next > Next > at step 3, under "column data format" choose "text" > Finish
That converts existing dates, if you have dates to enter which you want to enter as text you can add an apostrophe, as Polly says, or you can simply pre-format the entry column as text format.
It's not an error. Changing the format of a cell does not change the value that is stored in that cell. Excel stores dates as numerical values. What I think you want to do is change the numerical value into text that resembles a date. Try this formula in a new cell somewhere:
= TEXT(A1,"dd/mm/yyyy")
Enter your dates with an apostrophe at the beginning. '22/10/2013 will be interpreted as a text string.

"12/2013" in cell automatically changes to "12/1/2013"

in excel, how to prevent this automatic changing of values like: "12/2013" to "12/1/2013"
if i enter "12/2013" in a cell it is auto changed to "12/1/2013". i donot want this.
Because I want to search for exact "12/2013" later using vba.
You can either use ' as a prefix, i.e. enter '12/2013- or format the column/cell as text beforehand.
Right click on the cell(or cells after selecting them) -> Format Cells -> Number -> Text and re-enter the data of course.

Resources