I have this input box that collect amounts and then enters them in a cell:
Dim DEKPOSO As String
DEKPOSO = InputBox("enter the ammount?")
Sheets("ammounts").Range("E3").Value = DEKPOSO
When you enter the amount as 450.23 everything is fine, the cell registers as 450,23
The problem is I am in Greece and when I enter the amount 450.23 in the inputbox as normal (when greek language is selected) it displays in the cell correctly but it shows an error that the number is formated as text and partly won't calculate.
Related
I have copied (copy/paste) a part of a home-page into an empty excel. One of the fields looks like this: 3140:01:00. If I check the format, it shows that the category is custom, and that the type is [t]:mm:ss. The problem is that I am only interested in the first 4 digits shown plus digits 6 and 7. If I change the format to e.g. text, I end up with a number. Probably a number, that identifies a specific date. In fact the first 4 digits are the length of a horse race! :-) I'm new at VB, but I have managed to clean up the rest of the information - but not this. Probably a known problem. Please help!
You will need to understand the difference between the value and the representation of your data (note that this is not VBA but Excel related). When you enter 3140:01:00 in a cell in Excel, Excel tries to understand what you enter. With the colon, it looks somehow like a time value, so Excel guesses that this a a time, convert what you enter into a date value (a date in Excel has automatically a time part) and put a number format that displays this date+time as [h]:mm:ss.
As I said, internally, what you entered is converted into a Date. Now a Date in Excel in internally stored as a number. If you set the number format to "Number", the cell will display 130.83402. This is because 3140 hours = 130 days + 20 hours. The 20 hours (plus the 1 minute) are stored as a fraction of a day (0.83402).
If you format the same value as Date/Time, you will see (depending on your regional settings) something like 05/09/1900 20:01:00 - because that is the 130th day in the Excel calendar (day 1 in Excel is 1/1/1900). Note that the value of the cell doesn't change, only the way it is displayed.
If you could prevent Excel to convert your input into a date, the solution would be to do string-handling, eg use the Split-function. When you format a cell as Text and enter 3140:01:00 manually, Excel leaves the string untouched and this would work. However, it seems that when you Paste the value into the cell, the number format is set automatically and the value is converted into a date even if the cell was formatted as Text before. I don't know if there is a way to tell Excel to not convert the data if it is pasted.
So what we can do instead is to convert the date value back into "hours", "minutes" and "seconds" - even if the "hours" are in fact something else (meters? yards? horse length?), and the minutes are probably also not minutes but whatever.
Several ways to do so.
If you don't mind that the strange pseudo-date value remains in your Excel (you can hide the column with that value), use just 2 simple formulas. Assuming your "date" is in D2:
use the formula =TRUNC(24*D2) to get the horse race length (the first number). We cannot use the Hour-formula here as this would return only 20 and not 3140.
use the formula =MINUTE(D2) to get the second number
use the formula =SECOND(D2) to get the third number
If you want to involve VBA:
Sub SplitStrangeDate(cell As Range)
If Not IsDate(cell) Then Exit Sub
Dim d As Date
d = cell.Value
Dim v1 As Long, v2 As Long, v3 As Long
v1 = CLng(d * 24)
v2 = Minute(d)
v3 = Second(d)
Debug.Print v1, v2, v3
End Sub
How to get value from textbox in excel. I have 3 textbox, TextBox 1, TextBox 2, TextBox 3. How to SUM all three textbox to cell "A4". When I update textbox, the cell "A4" is change.
Bear in mind that text boxes contain text (strings), even in their Value property. Therefore their value must be converted to a number when summing up and the resulting number must be converted to text when it's assigned to TextBox4. Most of this VBA will do automatically most of the time. If you want your program to work correctly all the time you should consider giving instructions. The following code will create a value that can be assigned to a variable of Double data type.
Dim MySum As Double
MySum = Val(TextBox1.Value) + Val(TextBox2.Value) + Val(TextBox3.Value)
This Double can be assigned directly to a worksheet cell.
Cells(4, "A").Value = MySum
Be mindful that Cells(4, "A").Value = TextBox1.Value may not have the same effect because in one case a number is assigned, in the other a string.
In order to update Range("A4") when one of the text boxes changes value you should use the TextBox's BeforeUpdate event. The Change event fires whenever you type a character which will give you a lot of flicker because updates are run before the user finishes typing. With the Before or AfterUpdate events the updating of worksheet cell will occur when the text box being changed loses the focus.
I have formatted a cell in Excel as Scientific with 1 decimal place then I inserted a number in it like (0.41). After pressing enter the result displayed is (4.1E-01). My aim is to put this result in a cell with text format so that when I double click the cell, I can copy/modify the text (4.1E-01) as I want.
I tried to format that cell as text but the result gets back to 0.41. I also tried to copy the cell and paste the value only using "Special Paste" into a text-formatted cell but the result keeps returning to 0.41. Do you have a suggestion on how to solve this issue?
Thanks in advance
This is a bit of a work around unless you want to use VBA. In an adjacent cell type this formula:
=TEXT(A1,"0.00E+00")
Now you can copy that cell and paste values only and get just the text:
2.22E+27
If your okay with VBA use this:
Range("A2").Value = Range("A1").Text
I'm writing a MatLab programm under windows 7 x64 that takes the clipboard, with mixed data copied from Microsoft Excel, and import it directly to MatLab into a single char array.
When I use str = clipboard('paste') in MatLab, all text data copied from excel are fine, but the numerical data copied loss some decimal places.
For example, if the cell A1 contains the number 2113.12389881239, but it only displays the value 2113.123899 due to cell formating, then 2113.123899 is copied from excel to MatLab instead of the real cell value 2113.12389881239.
I would like to know how to copy the exact cell value stored in Excel not the value displayed.
Thanks in advance.
Given the following value: .1234567, formatted with all from 1-7 decimal places, I get the following results when I copy-paste to another program (notepad):
0.1
0.12
0.123
0.1235
0.12346
0.123457
0.1234567
Assuming you want to copy one number at a time, I used this macro:
Sub FormattedCopy()
Dim oldFormat, copyString As String
oldFormat = Selection.NumberFormatLocal
Selection.NumberFormatLocal = "#"
Selection.Copy
MsgBox ("Please paste your data")
Selection.NumberFormatLocal = oldFormat
End Sub
The message box serves to 'pause' the process, because changing the number format back will clear the clipboard. When I paste any value, it properly displays in notepad as 0.1234567
You can do this with a range of values if you save the range of number formats in an array and feed it back as I did above with for loops.
I have an input field where the user inputs a number "X.XXXXX"
I then copy that number using some VBA to another sheet when a button is pressed. The problem occurs when the number ends in 0 or multiple zeros. For example, take the number 5.46770. I have the cell formatted to display 5 decimal places. However, if the trailing number is a 0, Excel still considers the value to be 5.4677 unbeknownst to the user. So when my macro pull the value from the cell it takes 5.4677 vs. 5.46770. What I'm trying to figure out is how to have my VBA code pull the trailing 0(s). Any ideas?
The value of 5.4677 is the same as 5.46770; they are equal.
If you are trying to get a string that is formatted just like the cell, try:
cell.Text
Depending on what you are doing with the NUMBER, you could set the cell value with a single quote in front. It will force it to be shown like text, leading/trailing zeros or not. IE:
CELL2.VALUE = "'" & FORMATNUMBER(CELL1.VALUE,5)